我正在尝试在构建生产时使用UglifyJsPlugin删除console.log。但是,在生产模式下构建后,不会删除console.log代码。这是我用于删除console.log的webpack代码。
Webpack配置:
config.plugins.push(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
})); // for React
config.plugins.push(new webpack.optimize.OccurrenceOrderPlugin());
config.plugins.push(new webpack.optimize.UglifyJsPlugin({
minimize: true,
comments: false,
compress: {
drop_console: true
}
})); // minimize
config.plugins.push(new webpack.optimize.DedupePlugin()); // remove duplication
config.output.filename = "[name].[chunkhash].js";
config.output.chunkFilename = "[id].[chunkhash].bundle.js";
webpack模块:
module: {
loaders: [
{
test: /\.css$/,
loader: "css-loader"
},
{
test: /\.less$/,
loader: "css-loader!less-loader?{'paths': [\""+__dirname+"/src\", \""+__dirname+"/node_modules\"]}"
},
{
test: /\.png|\.gif|\.jpg|\.svg|\.eot|\.woff|\.woff2|\.ttf/, loader: "file-loader"
},
{
test: /\.json/,
loader: "json-loader"
},
{
test: /\.js$/,
exclude: /(node_modules|bower_components|plugins)/,
loader: 'babel-loader',
}]
}
我也在使用babeljs并且听说它可能是因为babeljs转换代码的原因。有谁知道如何处理这个?