requirejs-rails icon indicating copy to clipboard operation
requirejs-rails copied to clipboard

Use config.assests.js_compressor setting for save original js compressor

Open aar0nTw opened this issue 10 years ago • 8 comments

When I set config.assets.js_compressor to compressor with some custom options like Uglifier.new(mangle: false)
The precompile task always get the error: Sprockets::Error: unknown compressor: js_compressor, there's because Sprocket::Environment will return :js_compressor symbol when we want to get Rails.application.assets.js_compressor value if user set compressor to specific compressor object , please see https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/compressing.rb#L60

and when the task want to put orignal_js_compressor back to env.js_compressor, Sprocket can't find any compressor source name :js_compressor and throw error.

So it should be cache the Rails.application.config.assets.js_compressor(A real compressor object) to original_js_compressor not Rails.application.assets.js_compressor.

ref #201

aar0nTw avatar Dec 12 '14 12:12 aar0nTw

@aar0nTw Could you add a js_compressor attribute to Requirejs::Rails::Config and use that?

carsomyr avatar Dec 12 '14 21:12 carsomyr

Hi @carsomyr:

It already has optimize option for r.js build in build_config_whitelist, we can use optimize: uglify2 and set more option for detail build output in requirejs.yml.

I think it has no need to add attribute in requirejs rails config, We just need get the current sprocket compressor object, because the prepare_source task is call sprockets to get assets path and write it to requirejs source path for r.js build, so it temporarily disable the compress function of sprockets and restore it after the task end.

aar0nTw avatar Dec 13 '14 03:12 aar0nTw

@aar0nTw My main concern is clarity: The code in the Rake tasks refers to requirejs.config, so an effort should be made to adhere to that.

carsomyr avatar Dec 13 '14 04:12 carsomyr

@carsomyr updated, please check it

aar0nTw avatar Dec 16 '14 05:12 aar0nTw

Can we get this merged?

agis avatar Aug 18 '15 13:08 agis

@agis- Ok, I'll take a look at this again.

carsomyr avatar Aug 18 '15 19:08 carsomyr

Run into the same issue too, using requirejs-rails 1.9.5, rails 4.2, sprockets 2.12.4 and sprockets-rails.

@aar0nTw Are you using this patch in production?

agis avatar Sep 24 '15 11:09 agis

Also interested in this (requirejs-rails-0.9.9 / rails 4.2).

Dagnan avatar Sep 28 '15 23:09 Dagnan