webpack 4 禁用 uglifyjs-webpack-plugin
webpack 4 disable uglifyjs-webpack-plugin
过去 2 天我遇到了 个问题。所以我决定从 webpack 构建过程中完全禁用 uglifyjs-webpack-plugin
。我在 webpack 4 上找不到任何东西。
module.exports = {
optimization:{
minimize: false, // <---- disables uglify.
// minimizer: [new UglifyJsPlugin()] if you want to customize it.
}
}
如果您正在管理单个 webpack.config.js
并根据环境使用 package.json npmscripts
。您也可以使用这种方法。
您可以这样做:创建一个 defaultplugins 数组并检查环境,如果环境是 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"],
},
};
};
过去 2 天我遇到了 uglifyjs-webpack-plugin
。我在 webpack 4 上找不到任何东西。
module.exports = {
optimization:{
minimize: false, // <---- disables uglify.
// minimizer: [new UglifyJsPlugin()] if you want to customize it.
}
}
如果您正在管理单个 webpack.config.js
并根据环境使用 package.json npmscripts
。您也可以使用这种方法。
您可以这样做:创建一个 defaultplugins 数组并检查环境,如果环境是 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"],
},
};
};