I want Rails 3.1 to pick up more of my assets for precompilation. In particular, the default matcher for compiling files doesn't add .js
files from vendor/assets/javascripts
. I can just add the assets to the config.assets.precompile
list, but this seems annoying. I don't want to refer to them in the application.js
manifest, because I don't want them included in all pages.
In summary, any way to request that all .js
files found in vendor/assets/javascripts
get precompiled by rake assets:precompile
, but without having them included in all pages?
The default locations are: the images , javascripts and stylesheets directories under the app/assets folder, but these subdirectories are not special - any path under assets/* will be searched. Assets inside subdirectories can also be accessed. You can view the search path by inspecting Rails. application.
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.
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.
Generally asset is anything that browser loads after it gets the HTML page. Meaning javascript, css and any images. But as you pointed out there are two different image types in a rails project.
config.assets.precompile
accepts regular expressions and wildcard matching - so to ensure all js files get compiled, without specifying each by name, something like this should do the trick:
config.assets.precompile << '*.js'
I modified example given in Rails config.assets.precompile setting to process all CSS and JS files in app/assets and here is my version, which takes all assets from /app and /vendor except partials (starting from _)
config.assets.precompile << Proc.new { |path| if path =~ /\.(css|js)\z/ full_path = Rails.application.assets.resolve(path).to_path app_assets_path = Rails.root.join('app', 'assets').to_path vendor_assets_path = Rails.root.join('vendor', 'assets').to_path if ((full_path.starts_with? app_assets_path) || (full_path.starts_with? vendor_assets_path)) && (!path.starts_with? '_') puts "\t" + full_path.slice(Rails.root.to_path.size..-1) true else false end else false end }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With