config.assets.precompile not adding vendor/gem assets

北城余情 提交于 2019-12-04 00:13:37

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!