xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Webpack 4.x uglifyjs remove comments

Webpack 4.x uglifyjs remove comments

uglifyjs & uglifyjs-webpack-plugin

1. remove comments

const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
  // ...
  optimization: {
    minimizer: [
      new UglifyJsPlugin({
        uglifyOptions: {
          output: {
            // 2. remove comments
            comments: false,
          },
        },
      }),
    ],
  },
}

2. preserve comments

const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
  // ...
  optimization: {
    minimizer: [
      new UglifyJsPlugin({
        uglifyOptions: {
          output: {
            // ✅ preserve  comments
            comments: true,
          },
        },
      }),
    ],
  },
}

preserve comments

const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
  // ...
  optimization: {
    minimizer: [
      new UglifyJsPlugin({
        uglifyOptions: {
          output: {
            comments: /@license/i,
          },
        },
        extractComments: true,
      }),
    ],
  },
};

https://v4.webpack.js.org/plugins/uglifyjs-webpack-plugin/#preserve-comments

refs

https://github.com/webpack/webpack/issues/6879#issuecomment-785867797



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-02-25 20:48  xgqfrms  阅读(220)  评论(3编辑  收藏  举报