Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to strip comments in webpack bundle js file

I have been trying to strip comments in the webpack bundled js file. I have tried several methods but it's not working still and I get comments like

"/**\n * Copyright 2013-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\ ...

For this the bundled file is getting huge. Currently huge at 1.6mb size. I have tried this

new webpack.optimize.UglifyJsPlugin({
        sourceMap: false,
        compress: {
            sequences: true,
            dead_code: true,
            conditionals: true,
            booleans: true,
            unused: true,
            if_return: true,
            join_vars: true,
            drop_console: true
        },
        mangle: {
            except: ['$super', '$', 'exports', 'require']
        },
        output: {
            comments: false
        }
    })

also this

new webpack.optimize.UglifyJsPlugin({
        compress: { warnings: false },
        sourceMap: false,
        output: false
    })

Also set the enviroment to production

set NODE_ENV=production

I am not able to understand where I am wrong. Please help. Thanks in advance.

like image 387
Koushik Das Avatar asked Jan 30 '17 14:01

Koushik Das


Video Answer


1 Answers

For webpack 4 this was working for me:

// webpack.config.js

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

module.exports = {
  // other config properties...

  optimization: {
    minimizer: [
      new UglifyJsPlugin({
        uglifyOptions: {
          output: {
            comments: false
          }
        }
      })
    ]
  }
};

You can find more information in the official docs.

like image 91
laszlo-horvath Avatar answered Oct 24 '22 05:10

laszlo-horvath