Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

config.assets.precompile not adding vendor/gem assets

I'm having trouble getting vendorized assets to be compiled as root files.

I want to have the following assets available standalone (not packaged with other assets_:

vendor/gems/neo-viz/app/assets/stylesheets/neo-viz.css.scss
vendor/gems/neo-viz/app/assets/javascripts/neo-viz.js.coffee
vendor/gems/neo-viz/app/assets/javascripts/lib/jQuery/jquery-1.6.1.min.js
vendor/gems/neo-viz/app/assets/javascripts/lib/arbor/arbor.js

With the following line:

config.assets.precompile += %w( jquery-1.6.1.min.js arbor.js neo-viz.js neo-viz.css )

Only the css file is precompiled and made available. Why?

Also, after seeing this question ( Including assets in subdirectories with config.assets.precompile in Rails ), I tried:

config.assets.precompile += %w( jquery-1.6.1.min.js arbor.js neo-viz.js neo-viz.css lib/arbor/arbor.js arbor/arbor.js lib/jQuery/jquery-1.6.1.min.js jQuery/jquery-1.6.1.min.js   )

But it made no difference. Ideas?

like image 288
Peter Ehrlich Avatar asked Apr 08 '12 23:04

Peter Ehrlich


People also ask

How do you Precompile an asset?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

What does rake assets Clean do?

The clean it removes the old versions of the precompiled assets while leaving the new assets in place. Show activity on this post. rake assets:clean removes compiled assets. It is run by cap deploy:assets:clean to remove compiled assets, generally from a remote server.

What is Require_tree?

The require_tree directive tells Sprockets to recursively include all JavaScript files in the specified directory into the output. These paths must be specified relative to the manifest file.


1 Answers

By default Rails only looks into 3 locations: app/assets, lib/assets or vendor/assets. Sprockets looks for JS assets in the sub-directory javascripts. E.g.

app/assets/javascripts/arbor.js
lib/assets/javascripts/arbor.js
vendor/assets/javascripts/arbor.js

If you want to see where Rails is looking for you can use this in the console: Rails.application.config.assets.paths

What you can do is add your custom path to the pipeline:

 # @file: config/application.rb
 config.assets.paths << Rails.root.join("vendor", "gems", "neo-viz", "app", "assets", "javascripts")

Then create a manifest, where you include your JS files:

# @file: /vendor/gems/neo-viz/app/assets/javascripts/neo-viz.js
//= require lib/jQuery/jquery-1.6.1.min
//= require lib/arbor/arbor
//= require neo-viz

Finally add your manifest:

config.assets.precompile += %w( neo-viz.js )'

If you still want to add them separatly, which I do not see the point, why not include them in a manifest, then you'll have to add all the possible path prefix so Rails knows where to look:

 # @file: config/application.rb
 config.assets.paths << Rails.root.join("vendor", "gems", "neo-viz", "app", "assets", "stylesheets")
 config.assets.paths << Rails.root.join("vendor", "gems", "neo-viz", "app", "assets", "javascripts")
 config.assets.paths << Rails.root.join("vendor", "gems", "neo-viz", "app", "assets", "javascripts", "lib", "jQuery")
 config.assets.paths << Rails.root.join("vendor", "gems", "neo-viz", "app", "assets", "javascripts", "lib", "arbor")

Then you can add them like this, since assets outside a manifest must be added to the precompile array:

config.assets.precompile += %w( jquery-1.6.1.min.js arbor.js neo-viz.js neo-viz.css )

Source: 2.1 Asset Organization

like image 144
Max Avatar answered Oct 22 '22 22:10

Max