uglifier not working in rails

荒凉一梦 提交于 2019-12-18 04:14:09

问题


config/application.rb
...
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
config.assets.digest = true
config.assets.paths << "#{Rails.root}/vendor/assets/images" 
...


config/environment.rb
...
ENV['RAILS_ENV'] ||= 'production'
...

My gemfile
...
gem 'uglifier'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  #gem 'uglifier'
end
...

environment/production.rb
....
    config.active_support.deprecation = :notify
    config.assets.enabled = true
    config.assets.js_compressor  = :uglifier
    config.assets.css_compressor = :scss
    config.assets.compress = false
...

I have my javascript files in app/assets/javascripts. My javascript files are not getting compressed. Followed this url http://dev.mensfeld.pl/category/rails3/ to workout compression.

Thanks for any directions.


回答1:


In environment/production.rb:

...
config.assets.compress = true
...



回答2:


I had the same problem, & after much tearing of hair, discovered that you must change an asset file in order to trigger compression.

Seems that compression relies on asset file mtime, which makes sense, since one of the problems the asset pipeline intends to overcome is (from the Rails guide):

... when static assets are deployed with each new release of code, the mtime of all these files changes, forcing all remote clients to fetch them again, even when the content of those assets has not changed.




回答3:


use this command:

rake RAILS_ENV=production RAILS_GROUP=assets assets:precompile


来源:https://stackoverflow.com/questions/7371432/uglifier-not-working-in-rails

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