Question

I have a whole MESS of javascripts in vendor/assets/javascripts. In my app/assets/javascripts/application.js file, I have the directive:

//= require_tree .

Does that only reference the current app/assets/javascripts directory, and not lib/assets or vendor/assets?

If I explicitly include the javascripts, it works. I just don't really want to do that if I don't have to.

Is there something I am missing that will allow the assets pipeline to be able to serve up assets from outside the app directory (lib and vendor) automatically?

Was it helpful?

Solution

require_tree only pulls in assets that are under the application.js file.

lib/assets and vendor/assets are already included in the lookup paths for the pipeline (refer this code).

You can include these vendored files by using a second manifest.

Go to vendor/assets/javascripts and create a file called misc_vendor.js

Inside that add put a require_tree directive.

Then refer to that file from your application.js manifest:

require misc_vendor

If you have any issues because of loading order you can manually require the vendor files in the order you need instead of using require_tree.

As part of the conversion to the pipeline it may be a good chance to clean up things! :-)

OTHER TIPS

Also, you can do it without a second manifest like this:

//= require_tree ../../../vendor/assets/javascripts/.

The path should be relative to the 'app/assets/javascripts/application.js' manifest file.

You need to extend path in application.rb file like this.

config.assets.paths << "#{Rails.root}/vendor/assets/some file name"

Refer this Guide for more details

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top