/etc

tags: rails
Originally Published: 2020-12-01

Want to avoid embarassing JavaScript console output in a production Rails app that’s using Webpacker?

if you ever feel like aren't a good webdev you can just go to ostensibly professional large scale consumer production websites and just open up the console and look at shit like this pic.twitter.com/BwLftTvyVy

— Nicole He (@nicolehe) November 29, 2020

It’s easy! Just pass drop_console = true into your Webpack’s “Terser” configuration (what Webpack uses for minification), and console output should be stripped from all your Webpacker assets.

As it turns out, other people have also found this confusing, and a helpful GitHub issue comment has the solution:

In your config/webpack/production.js, after the const environment line simply add the following:

environment.config.optimization.minimizer.find(m => m.constructor.name === 'TerserPlugin').options.terserOptions.compress.drop_console = true

Commit, reload, and enjoy the amazing freedom of using console.log in development without worrying about it leaking into production.