在过去的 2 天里,我遇到了这个问题。所以我决定完全禁用uglifyjs-webpack-plugin
webpack 构建过程。我在 webpack 4 上找不到任何东西。
问问题
13247 次
2 回答
41
module.exports = {
optimization:{
minimize: false, // <---- disables uglify.
// minimizer: [new UglifyJsPlugin()] if you want to customize it.
}
}
于 2018-07-10T11:54:38.310 回答
0
如果您正在管理单个webpack.config.js
并package.json npmscripts
基于环境使用。您也可以使用这种方法。
您可以执行以下操作:创建一个 defaultplugins 数组并检查环境,如果 environment 是 prod,则推送到数组,否则使用 defaultplugins。如示例所示:
package.json
"config-prod": "webpack --env.NODE_ENV=prod --parallel build-webpack",
"build-prod": "npm run config-prod"
webpack.config.js
仅添加了相关部分,以便于阅读
var webpack = require("webpack");
var path = require("path");
const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const webpackUtilities = require("./webpack.utilities");
module.exports = (env) => {
var defaultplugins = [
new webpack.DefinePlugin({
///// section deleted
}),
new MiniCssExtractPlugin({
///// section deleted
}),
];
return {
mode: env.NODE_ENV == "prod" ? "production" : "development",
devtool: env.NODE_ENV == "prod" ? "" : "source-map";,
entry: {
///// section deleted
},
output: {
///// section deleted
},
module: {
rules: [
{
///// section deleted
},
],
},
plugins:
env.NODE_ENV == "prod"
? [...defaultplugins, new UglifyJSPlugin()]
: [...defaultplugins],
resolve: {
extensions: [".js", ".jsx", ".scss", ".css"],
},
};
};
于 2020-09-29T16:33:51.590 回答