Search code examples
minifywebpack-2

Keep comments in webpack?


So consider the following script command to run via npm run: webpack -p --optimize-minimize

Is there any way to say: Keep comments?

webpack version 2 is used.

In most applications you would not want to keep comments, but in this particular case I want to keep them, while still minifying the "script" Is this possible?


Solution

  • Webpack's webpack.optimize.UglifyJsPlugin has a couple of options which might fit your needs.

    comments options accepts a regex or function to tell UglifyJs which comment to preserve.

    extractComments let you even extract the comments to separate txt files.

    Set it up like this:

    plugins: [
        new webpack.optimize.UglifyJsPlugin({
            comments: true, // or function/regex
            // Further UglifyJs config
        })
    ],