I have had this problem for the last 2 days. So I decided to completely disable uglifyjs-webpack-plugin from webpack build process. I was not able to find anyth
module.exports = {
optimization:{
minimize: false, // <---- disables uglify.
// minimizer: [new UglifyJsPlugin()] if you want to customize it.
}
}
If you are managing single webpack.config.js
and using package.json npmscripts
based on environment. You can use this approach as well.
You can do something like this: creating a defaultplugins array and check the environment, if environment is prod, the push to array otherwise use defaultplugins. as shown in example:
package.json
"config-prod": "webpack --env.NODE_ENV=prod --parallel build-webpack",
"build-prod": "npm run config-prod"
webpack.config.js
Added only relevant sections, so that it's easy to read
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"],
},
};
};