hmdne / roda-sprockets

MIT License
5 stars 1 forks source link

js_compressor option not work? #4

Closed zw963 closed 3 years ago

zw963 commented 3 years ago

Following is my roda plugin config

  plugin :sprockets, precompile: ['app.js', 'app.scss'],
    root: Dir.pwd,
    public_path: 'public/',
    opal: true,
    js_compressor: 'uglify',
    debug: ENV['RACK_ENV'] != 'production'

i change above uglify to "uglifier", :uglifier, :uglify, both of the not work, after run rake assets:precompile, i only get a compiled js file without minify, like this.

image

zw963 commented 3 years ago

For more detail, please check my app on https://github.com/zw963/marketbet_crawler

zw963 commented 3 years ago

Sorry, it works, because i am not set RACK_ENV=production, and must specify js_compressor like this:

plugin :sprockets, precompile: ['app.js', 'app.scss'],
    public_path: 'public/',
    opal: true,
    js_compressor: Uglifier.new(:harmony => true),
    debug: ENV['RACK_ENV'] != 'production'
zw963 commented 3 years ago

Hi, @hmdne , i spent hours for find out why js_compressor options not work when RACK_ENV is not set to production. I test use another JS library (terser), it same behavior as uglifier.

I check almost all of the source code of roda-sprockets, sprockets gem, try to find out if somewhere have a condition statement for indicate current assets precompile should use minify and others options, but no luck,

If you have time, could you please give me some clue about this?

hmdne commented 3 years ago

@zw963 It should have been documented certainly or the debug mode should be disabled automatically when building assets.

zw963 commented 3 years ago

@zw963 It should have been documented certainly or the debug mode should be disabled automatically when building assets.

No, it not controlled by debug option, following is my new config:

plugin :sprockets, precompile: ['app.js', 'app.scss'],
    public_path: 'public/',
    opal: true,
    js_compressor: Terser.new,
    debug: true   # => set debug always true.

if i set RACK_ENV to production to run rack task, i will generated minified version, if not, will generate normal version. so, it only controlled by this ENV.

hmdne commented 3 years ago

You are right! I will correct this behavior in the next commit