Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terser is executed twice, when explicit configured as minimizer #1564

Closed
CGollhardt opened this issue May 18, 2020 · 9 comments
Closed

Terser is executed twice, when explicit configured as minimizer #1564

CGollhardt opened this issue May 18, 2020 · 9 comments
Labels

Comments

@CGollhardt
Copy link

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

@sokra
Copy link
Member

sokra commented May 18, 2020

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.

@CGollhardt
Copy link
Author

CGollhardt commented May 19, 2020

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({})

@alexander-akait
Copy link
Member

Bug in webpack-cli

@alexander-akait alexander-akait transferred this issue from webpack/webpack May 20, 2020
@alexander-akait
Copy link
Member

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

@anshumanv
Copy link
Member

anshumanv commented May 20, 2020

@evilebottnawi is it because we've specified devtool in production config which is used when mode production/development?

@alexander-akait
Copy link
Member

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

@alexander-akait
Copy link
Member

alexander-akait commented May 20, 2020

webpack provides default configuration for a mode out of box

@anshumanv
Copy link
Member

Will fix

@alexander-akait
Copy link
Member

Fixed #1565

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants