开发者

uglifier gem with rails 3.0

The rails 3.1 has as default a great gem named uglifier for js minificatio开发者_开发问答n.

To enable it, we just have to call

config.assets.js_compressor  = :uglifier

I'm working in another project, rails 3.0, and I want to use as well the same gem. I searched already some info, but i couldn't not find any direction. Something that i found, in the rdoc is

require 'uglifier'
Uglifier.new.compile(File.read("source.js"))
# => js file minified

I can write a rake task maybe to execute it, it's fine, but there is any other way?

update:

i'm using barista and coffeescript, so maybe there is something that i can add to barista to generate the js already minified


Barista has hooks. If you look at your config/initializers/barista_config.rb, it tells you what all the hooks are. So, for example, I decided not to go with Jammit but instead minify using the JSMin gem. Inside my barista_config.rb I put this:

Barista.configure do |c|
  c.on_compilation do |path|
    if Rails.env.production?
      puts "+++ Barista: Compressing #{path} for production environment +++"
      compressible = File.read(path)
      File.open(path, 'w'){|f| f.write(JSMin.minify(compressible))}
    end
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜