feat(v2): env variable TERSER_PARALLEL to customize TerserPlugin.parallel (#3497)

* fix(v2): disable terser parallel on CIs

Do not run Terser in parallel when using CircleCI or similar CI environments
to avoid "Error: Call retries were exceeded" errors. For more information
see https://github.com/webpack-contrib/terser-webpack-plugin#parallel

`CI=true` is true for:
- https://docs.gitlab.com/ee/ci/variables/#debug-logging
- https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables
- https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables
- https://docs.travis-ci.com/user/environment-variables/

* fix(v2): check for possibly undefined env variable

* fix(v2): configurable terser parallelization

* fix(v2): correct terser codedoc

* fix(v2): explicitly test for undefined

* fix(v2): add radix to parseInt

* fix(v2): add missing semicolon

* fix(v2): resolve prettier issues

* fix(v2): resolve remaining prettier issues
This commit is contained in:
hackerman 2020-09-29 16:42:08 +02:00 committed by GitHub
parent d3a01458a3
commit db051eef4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,6 +38,17 @@ export function excludeJS(modulePath: string): boolean {
);
}
// See https://github.com/webpack-contrib/terser-webpack-plugin#parallel
let terserParallel: boolean | number = true;
if (process.env.TERSER_PARALLEL === 'false') {
terserParallel = false;
} else if (
process.env.TERSER_PARALLEL &&
parseInt(process.env.TERSER_PARALLEL, 10) > 0
) {
terserParallel = parseInt(process.env.TERSER_PARALLEL, 10);
}
export function createBaseConfig(
props: Props,
isServer: boolean,
@ -103,7 +114,7 @@ export function createBaseConfig(
? [
new TerserPlugin({
cache: true,
parallel: true,
parallel: terserParallel,
sourceMap: false,
terserOptions: {
parse: {