3

We have a Grails app with loads of javascript files in the /web-app/js folder and we recently installed the Asset Pipeline Plugin... but just recently. The app is a few years old now.

We don't want to move all js files from /web-app/js folder to /grails-app/assets/javascripts folder since we might break some of the gsp files that are using those resources directly.

Let's suppose we have the file: /web-app/js/myscript.js

We want to create a matching file in the assets folder... /grails-app/assets/javascripts/myscript.js

... but that file should be empty except for one line like:

//=require /web-app/js/myscript.js

So the file in the assets folder only points to the real file in web-app folder. The problem is that the above manifest line does not work.

The above might not make too much sense for just one file. But what we really want is to include several files (that already exist in /web-app/js folder) and use the Asset Pipeline Plugin to compile them all.

Is it possible? Thanks a lot.

user3621841
  • 815
  • 2
  • 10
  • 18

1 Answers1

1

Unless the default changed in the more recent versions of the asset pipeline, just lose the /web-app prefix - the plugin searches both locations for compatibility reasons (think of all the plugins that aren't asset pipeline aware and would have to be modified..)

EDIT: in fact, looking at the Asset Pipeline documentation, you can loose /js as well since all folders under /web-app will be searched for the referenced file name.

Gregor Petrin
  • 2,891
  • 1
  • 20
  • 24
  • Thanks Gregor. But it does not work. We tried `"myscript.js", "js/myscript.js", "/js/myscript.js", "web-app/js/myscript.js"` etc and none of them work. The ONLY one that kind of worked was `"../../../web-app/js/myscript.js"` but that ends up pointing to itself generating the markup: `` We tried to change the name of the file in assets folder to "_myscript.js" but that did not work either – user3621841 May 09 '14 at 20:52
  • Does it work if you just put everything, including the 'manifest' file, in `web-app/js`? Just skip `assets/javascript` completely? – Gregor Petrin May 09 '14 at 21:40
  • Nope. If you add the line `` on the gsp file, the generated markup is `` which returns a non-existing file (since the file is in the primary web-app and not in assets folder) – user3621841 May 09 '14 at 22:43
  • 3
    Hmm, looked at the source and tried making a sample app, it's indeed impossible to include web-app assets unless they're in a plugin. So if you pack your javascripts into a plugin and include them into the app (via `grails.plugin.location`, see http://stackoverflow.com/questions/16115635/how-to-use-grails-plugin-location) both the old and the new code should work.. It's really not a lot of work and you can keep the plugin under the same root folder as the rest of the app, but you may get some confused developers who won't be able to find the javascript files at first :) – Gregor Petrin May 12 '14 at 08:00