DEV Community

xgqfrms
xgqfrms

Posted on

1 1

Answer: Remove console.logs with Webpack & Uglify

webpack 4.x remove console.log solutions

  1. only remove the console.log but leave other consoles (recommend ✅)

pure_funcs: ['console.log']

const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
// webpack.config.js
module.exports = {
    // ...
    optimization: {
        minimizer: [
            new UglifyJSPlugin({
                uglifyOptions: {
                    compress: {
                        pure_funcs: [
                            'console.log',
                            // 'console.error',
                            // 'console.warn',
                            // ...
                        ],
                    },
                    //

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay