Asset pipeline with rails/sprockets & bower

808 Views Asked by At

I am using rails/sprockets to manage my asset pipeline and bower to manage my assets.

When I run the following code to precompile my assets, all assets within the vendor/assets/bower_components get minified.

RAILS_ENV=production rake assets:precompile

Is it possible to only minify and concatenate the files specified in the application.js and application.css files along with the pictures and fonts?

In application.rb, I have the following lines:

config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.ico)
config.assets.paths << Rails.root.join('vendor', 'assets', 'bower_components', 'bootstrap-sass-official', 'assets', 'fonts')
config.assets.precompile << %r(.*.(?:eot|svg|ttf|woff)$)
config.assets.precompile = ['*.js', '*.css', '*.css.erb']

The biggest issue is that sprockets tries to precompile all assets including bootstrap-sass-official which I do not use and in doing so I get the following error:

 Sass::SyntaxError: Undefined variable: "$alert-padding".
 (/vendor/assets/bower_components/bootstrap-sass-official/assets/stylesheets/bootstrap/_alerts.scss:10)

I didn't even change the _alerts.scss file.

1

There are 1 best solutions below

0
On
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.ico)
config.assets.paths << Rails.root.join('vendor', 'assets', 'bower_components', 'bootstrap-sass-official', 'assets', 'fonts')
config.assets.precompile << %r(.*.(?:eot|svg|ttf|woff)$)
config.assets.precompile = ['*.js', '*.css', '*.css.erb']

This last line overwrites the previous two lines which add the image assets to precompile list, and instead compiles every javascript and css file which includes those in bootstrap gem.

You need confine that list by explicitly adding the files you need to be precompiled. Also, make that a += instead of a =.