如何从生产中删除console.log?

时间:2019-01-18 15:51:49

标签: laravel-mix

如何从生产中删除所有console.log。此代码不适用于 laravel-mix 4.x

webpack.mix.js

mix
    .js('resources/js/app.js', 'public/js')

if (mix.inProduction()) {
    mix.options({
      uglify: {
        uglifyOptions: {
          warnings: false,
          comments: false,
          beautify: false,
          compress: {
            drop_console: true,
          }
        }
      }
    });

    mix.version();
}

1 个答案:

答案 0 :(得分:1)

使用laravel-mix 4.x,他们将uglify替换为terserChangelog)。您必须更改 webpack.mix.js

if (mix.inProduction()) {
    mix.options({
        terser: {
            terserOptions: {
                compress: {
                   drop_console: true
                }
            }
        }
    });

    mix.version();
}