feat: support array of minimizers for minify and terserOptions#666
Merged
Conversation
The `minify` option now accepts an array of minifier functions that are executed sequentially, piping the code (and source map) of each step into the next. `terserOptions` can correspondingly be an array of option objects (index-paired with `minify`) or a single object shared by every minimizer. Warnings, errors and extracted comments from all minimizers are merged. Matches the array support already available in html-minimizer-webpack-plugin.
When a step in the `minify` array does not return a `code` string, keep the last-known-good code (or original input) and feed it to the next step, rather than breaking out of the loop. Errors and warnings from the skipped step are still surfaced. If no step in the chain ever produces code, the existing "Minimizer doesn't return result" error still fires. Matches the behavior in html-minimizer-webpack-plugin.
Moves the previously-private TerserPlugin.getEcmaVersion static method into src/utils.js (where the minimizer functions live), since the ecma-version derivation only matters for the minimizers that consume ecma (terserMinify, swcMinify). The plugin now imports getEcmaVersion from utils.js. No behavior change.
Some minimizers legitimately return only warnings, errors or extracted comments without producing new code. The plugin previously pushed a spurious "Minimizer doesn't return result" error in that case, on top of any real diagnostics the minimizer emitted. Now: * no synthetic error is added when `code` is `undefined` * warnings and errors from the minimizer are still surfaced * the LICENSE file is still emitted when `extractedComments` are returned without code; the banner is only prepended when a new source replaces the asset * the main asset is left unchanged when no minimizer in the chain produces code
Map more of webpack's `output.environment` flags to ECMAScript versions and pick the highest matching version when several flags are set: * ES2015 now also includes `methodShorthand` and `templateLiteral` * ES2017 added — triggered by `asyncFunction` * ES2020 now also includes `dynamicImportInWorker`, `globalThis` and `optionalChaining` Previously the function checked ES2015 before ES2020, so an environment that supported both (e.g. webpack production defaults) was downgraded to ES2015 — which left ES2017–ES2020 minification opportunities on the table. Now the highest version wins. Effect: when webpack signals modern features, swcMinify can now drop the unused `catch (e)` binding (ES2019 optional catch binding), which shows up in the updated snapshots.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #666 +/- ##
==========================================
+ Coverage 96.76% 97.36% +0.60%
==========================================
Files 3 3
Lines 340 380 +40
Branches 125 152 +27
==========================================
+ Hits 329 370 +41
+ Misses 11 10 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
minifyoption now accepts an array of minifier functions that areexecuted sequentially, piping the code (and source map) of each step into
the next.
terserOptionscan correspondingly be an array of option objects(index-paired with
minify) or a single object shared by every minimizer.Warnings, errors and extracted comments from all minimizers are merged.
Matches the array support already available in html-minimizer-webpack-plugin.