Skip to content

Instantly share code, notes, and snippets.

@wdmtech
Last active September 19, 2019 01:25
Show Gist options
  • Save wdmtech/73499479f1013689de64514ad9d02a10 to your computer and use it in GitHub Desktop.
Save wdmtech/73499479f1013689de64514ad9d02a10 to your computer and use it in GitHub Desktop.
Vue config for latest vue-cli-service to strip out/remove console statements in production environments

But the solution’s not beautiful 🙈

There’s a bug with uglify-es, which requires using the following in your package.json to force dependencies to use this version:

"resolutions": {
  "uglify-es": "3.3.9"
},

But that will enable the following to work:

// vue.config.jsconst UglifyJSPlugin = require('uglifyjs-webpack-plugin')module.exports = {
 configureWebpack: config => {
  if (process.env.NODE_ENV === 'production') {
   // mutate config for production...
   config.optimization.minimizer = [
    new UglifyJSPlugin({
     uglifyOptions: {
      compress: {
       drop_console: true,
      }
     }
    })
   ]
  }
 }
}


And voíla; no more `console.log` in production with the latest vue CLI service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment