Skip to content

Instantly share code, notes, and snippets.

@iMagesh
Forked from mrbongiolo/precompile.md
Created February 15, 2016 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iMagesh/5f3e481ce233c47b64e5 to your computer and use it in GitHub Desktop.
Save iMagesh/5f3e481ce233c47b64e5 to your computer and use it in GitHub Desktop.
HOW TO: Rails 4.2 add 'vendor/asset' to precompile list

To enable the precompilation of all non.js/.css assets within vendor/assets just add this to config/initializers/assets.rb:

Rails.application.config.assets.precompile << Proc.new { |path, fn| fn =~ /vendor\/assets/ && !%w(.js .css).include?(File.extname(path)) }

Be aware that this will precompile ALL non .js/.css assets that you have there, some plugins or libraries might have .txt or other files around, and those would end up into your precompiled list also.

If you need to precompile images only, you could use this:

Rails.application.config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
# or this
Rails.application.config.assets.precompile << /\.(?:png|jpg|jpeg|gif)\z/

If you need to precompile fonts only, you could use this:

Rails.application.config.assets.precompile += %w(*.svg *.eot *.woff *.ttf)
# or this
Rails.application.config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/

If you would like to precompile everything within vendor/assets/images:

Rails.application.config.assets.precompile << Proc.new { |path, fn| fn =~ /vendor\/assets\/images/ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment