Webpack-cli: Terser is executed twice, when explicit configured as minimizer

Created on 18 May 2020  路  9Comments  路  Source: webpack/webpack-cli


Bug report




What is the current behavior?
It seems the default terser is executed, even if configured a custom one

  • default *.LICENSE.txt, and custom *.OTHER.LICENSE.txt is created
  • even if disabled, sourceMap is generated

Output

If the current behavior is a bug, please provide the steps to reproduce.
Have the following optimization:

const TerserPlugin = require('terser-webpack-plugin');
optimization = {
    minimizer:
    [
        new TerserPlugin({
            sourceMap: false,
            extractComments: {
                filename: (fileData) => {
                    return `${fileData.filename}.OTHER.LICENSE.txt${fileData.query}`;
                }
            }
        })
    ]
}






What is the expected behavior?

Terser is not executed twice.


Other relevant information:
webpack version:
^5.0.0-beta.16
terser version:
^3.0.1
Node.js version:
12.16.3
Operating System:
Windows 10

Bug

All 9 comments

Thanks for your report. It would be great if you reduce your issue to a small reproducible example. Best put this example into a github repository together with instructions how to get to the problem.

Hello @sokra, thanks for your response. Excuse me for not posting a link to a github repro. I need to setup a environment for it first (Still using TFS).

You can download below files here.

All in the same directory:

package.json

{
  "name": "repro",
  "version": "2020.1.0",
  "private": true,
  "dependencies": {
    "jquery": "^3.4.1"
  },
  "devDependencies": {
    "terser-webpack-plugin": "^3.0.1",
    "webpack": "^5.0.0-beta.16",
    "webpack-cli": "^4.0.0-beta.8"
  },
  "scripts": {
    "build:production": "webpack --progress --mode production --config ./webpack.config.js"
  }
}

webpack.config.js

const path = require('path');
const dirname = __dirname;
const TerserPlugin = require('terser-webpack-plugin');

module.exports = () => {
    const config = {
        entry: './main.js',
        output: {
            path: path.join(dirname, 'dist'),
            filename: '[name].js',
            ecmaVersion: 5
        },
        optimization: {
            minimizer:
            [
                new TerserPlugin({
                    sourceMap: false,
                    extractComments: {
                        filename: (fileData) => {
                            return `${fileData.filename}.OTHER.LICENSE.txt${fileData.query}`;
                        }
                    }
                })
            ]

        }
    }

    return config;
};

main.js

import $ from 'jquery';
window.$ = $;

Execute:

  • npm install
  • npm run build:production

Current Output:

Output

Expected Output:

only main.js and main.js.OTHER.LICENSE.txt

Just to be clear, where I am coming from:

My intention is not to change the License.txt, but I want to change the terser configuration. I basicaly got this error, when trying to add Terser as a minifier:

[webpack-cli] The comment file "main.js.LICENSE.txt" conflicts with an existing asset, this may lead to code corruption, please use a different name

Using new TerserPlugin({})

Bug in webpack-cli

/cc @webpack/cli-team high priority, mode should not add plugins/loaders/etc, it should just set mode to production only

@evilebottnawi is it because we've specified devtool in production config which is used when mode production/development? https://github.com/webpack/webpack-cli/blob/dec153e428b584e9480e1ae51657a718663a16ab/packages/webpack-cli/lib/utils/production-config.js#L8

@anshumanv we should not merge this config in production mode, it is a whole invalid logic, just set compiler.mode to production

webpack provides default configuration for a mode out of box

Will fix

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anshumanv picture anshumanv  路  3Comments

evenstensberg picture evenstensberg  路  5Comments

sumukhah picture sumukhah  路  3Comments

snitin315 picture snitin315  路  5Comments

jbottigliero picture jbottigliero  路  5Comments