Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aar0nTw
Copy link

@aar0nTw aar0nTw commented Dec 12, 2014

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

@carsomyr
Copy link
Collaborator

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

@aar0nTw
Copy link
Author

aar0nTw commented Dec 13, 2014

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.

@carsomyr
Copy link
Collaborator

@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.

If user doesn't set the `config.requirejs.js_compressor, use
js_compressor of Sprockets in default.
@aar0nTw
Copy link
Author

aar0nTw commented Dec 16, 2014

@carsomyr updated, please check it

@agis
Copy link
Contributor

agis commented Aug 18, 2015

Can we get this merged?

@carsomyr
Copy link
Collaborator

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

@agis
Copy link
Contributor

agis commented Sep 24, 2015

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?

@Dagnan
Copy link

Dagnan commented Sep 28, 2015

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants