本文介绍了Webpack V4:使用Webpack&删除console.logs丑化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

此答案以前就像一个咒语:

This answer worked like a charm previously:

但是,由于Webpack v4不再起作用。从那以后它抛出:

However, since Webpack v4 it doesn't work anymore. Since then it throws:

要使它在Webpack v4中工作,需要什么?

我尝试使用以下方法没有运气:

I've tried using the following without luck:

const uglifyJsPlugin = require('uglifyjs-webpack-plugin');

if (process.argv.indexOf('-p') !== -1) {
  // compress and remove console statements. Only add this plugin in production
  // as even if drop_console is set to false, other options may be set to true
  config.plugins.push(new uglifyJsPlugin({
    compress: {
      'drop_console': true
    }
  }));
}


推荐答案

在config.plugins中,您是否尝试过将其放入config.optimization.minimizer中?

You're still putting it in config.plugins, have you tried putting it in config.optimization.minimizer?

const UglifyJSPlugin = require('uglifyjs-webpack-plugin')

...

optimization: {
  minimizer: [
    new UglifyJSPlugin({
      uglifyOptions: {
        compress: {
          drop_console: true,
        }
      }
    })
  ]
}

这篇关于Webpack V4:使用Webpack&删除console.logs丑化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:20