webpack 4 disable uglifyjs-webpack-plugin
Asked Answered
V

2

20

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 anything on webpack 4.

Varityper answered 10/7, 2018 at 11:0 Comment(0)
W
49
module.exports = {
    optimization:{
        minimize: false, // <---- disables uglify.
        // minimizer: [new UglifyJsPlugin()] if you want to customize it.
    }
}
Wraf answered 10/7, 2018 at 11:54 Comment(0)
R
0

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"],
    },
  };
};

Rottenstone answered 29/9, 2020 at 16:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.