Minification with Both Uglifier and esbuild

Curated ago by @jeremysmithco

Description

If you are working on legacy Rails projects with old ES5 code, but have also switched to jsbundling-rails, esbuild for new ES6 code, you may have struggled to find a good approach to minifying all your assets. Uglifier only works with ES5 and may cause issues in Harmony mode.

Inspiration for this approach came from Optionally skip compression for specific files and Custom sprockets compressor as proxy skips minified assets.

1
2
3
4
Rails.application.configure do
  # Compress JavaScript using a preprocessor.
  config.assets.js_compressor = :legacy_compressor
end