webpack 4 disable uglifyjs-webpack-plugin

前端 未结 2 946
北海茫月
北海茫月 2021-02-04 05:51

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

相关标签:
2条回答
  • 2021-02-04 05:56
    module.exports = {
        optimization:{
            minimize: false, // <---- disables uglify.
            // minimizer: [new UglifyJsPlugin()] if you want to customize it.
        }
    }
    
    0 讨论(0)
  • 2021-02-04 06:07

    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"],
        },
      };
    };
    
    
    0 讨论(0)
提交回复
热议问题