Support options for compressors in Sprockets #2693

Closed
masterkain opened this Issue Aug 25, 2011 · 3 comments

Comments

Projects
None yet
3 participants
@masterkain
Contributor

masterkain commented Aug 25, 2011

https://github.com/rails/rails/blob/master/actionpack/lib/sprockets/railtie.rb#L74

By setting:

config.assets.js_compressor = :closure

I'm unable to pass compressor options, such as changing the compilation_level for the closure-compiler gem to 'ADVANCED_OPTIMIZATIONS', which is the main reason I want to use this gem.

Granted I can write my own compressor, but ultimately I'd define something like config.assets.js_compressor_options which does take a hash. It is left to the user to pass proper options, if supported at all, to their underlining compressor of their choice.

@masterkain

This comment has been minimized.

Show comment
Hide comment
@masterkain

masterkain Aug 25, 2011

Contributor

Upon further inspection I came around with this:

# Compress JavaScripts and CSS
config.assets.compress = true
# config.assets.js_compressor = :closure
require 'closure-compiler'
config.assets.js_compressor = Closure::Compiler.new(compilation_level: 'ADVANCED_OPTIMIZATIONS')

Passing directly your own constructor works fine it seems.

I'll leave the thread open for eventual comment, feel free to close if passing a options constructor it's not a wanted feature.

Contributor

masterkain commented Aug 25, 2011

Upon further inspection I came around with this:

# Compress JavaScripts and CSS
config.assets.compress = true
# config.assets.js_compressor = :closure
require 'closure-compiler'
config.assets.js_compressor = Closure::Compiler.new(compilation_level: 'ADVANCED_OPTIMIZATIONS')

Passing directly your own constructor works fine it seems.

I'll leave the thread open for eventual comment, feel free to close if passing a options constructor it's not a wanted feature.

@masterkain masterkain closed this Dec 16, 2011

@alex88

This comment has been minimized.

Show comment
Hide comment
@alex88

alex88 May 2, 2013

Contributor

I know it's a pretty old thread, wouldn't be better to pass arguments after the first to the compressor constructor? like:

config.assets.js_compressor = :closure, :compilation_level => 'ADVANCED_OPTIMIZATIONS'

It seems cleaner to me since you don't need to add a require and instantiate the compressor there

Contributor

alex88 commented May 2, 2013

I know it's a pretty old thread, wouldn't be better to pass arguments after the first to the compressor constructor? like:

config.assets.js_compressor = :closure, :compilation_level => 'ADVANCED_OPTIMIZATIONS'

It seems cleaner to me since you don't need to add a require and instantiate the compressor there

@pickhardt

This comment has been minimized.

Show comment
Hide comment
@pickhardt

pickhardt Jan 29, 2014

@alex88 - that gives a syntax error

Uncaught exception: /Users/jeffp/projects/myapp/config/application.rb:67: syntax error, unexpected tASSOC

config.assets.js_compressor = :closure, :compilation_level => 'ADVANCED_OPTIMIZATIONS'
                                                            ^

@alex88 - that gives a syntax error

Uncaught exception: /Users/jeffp/projects/myapp/config/application.rb:67: syntax error, unexpected tASSOC

config.assets.js_compressor = :closure, :compilation_level => 'ADVANCED_OPTIMIZATIONS'
                                                            ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment