Update: Webpacker v5, -= Coffeescript

Today I’ve updated webpacker to v5 and have started to remove Coffeescript. To remove Coffeescript, remove it from your Gemfile, then find app -iname '*.coffee' and convert each file back into Javascript. You can plonk the coffeescript into the Try CoffeeScript web app. Once you’ve done and are moving the changes to production, it’s important to clear out your rails cache with rake tmp:cache:clear

If you’re using Uglifer to compress Javascript and you’re using ES6, you’ll need to tell Uglifier to use “Harmony” mode:

config.assets.js_compressor = Uglifier.new(harmony: true)

Alternatively switch to Terser – you’ll need to set it up as a JS compressor:

Sprockets.register_compressor 'application/javascript', :terser, Terser::Compressor
Rails.application.configure do
  config.assets.js_compressor = :terser

Leave a comment