From 3fc1068e4c256b27a534afaf2d6ec8c82a04dabc Mon Sep 17 00:00:00 2001 From: Jan Gosmann Date: Fri, 2 Feb 2024 15:38:15 +0100 Subject: [PATCH] fix: always read modernTargets option (fix: #15788) If `modernPolyfills` is set to `true`, but `renderLegacyChunks` is set to false, `genLegacy` will be false and we would return early. If this return happens before `modernTargets` is initialized, the modern polyfills will be generated with the wrong (the default?) target instead of the specified `modernTargets`. --- packages/plugin-legacy/src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index d7f0bb206547aa..54ffd41a193ece 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -325,6 +325,10 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { } config = _config + modernTargets = options.modernTargets || modernTargetsBabel + isDebug && + console.log(`[@vitejs/plugin-legacy] modernTargets:`, modernTargets) + if (!genLegacy || config.build.ssr) { return } @@ -335,10 +339,6 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { 'last 2 versions and not dead, > 0.3%, Firefox ESR' isDebug && console.log(`[@vitejs/plugin-legacy] targets:`, targets) - modernTargets = options.modernTargets || modernTargetsBabel - isDebug && - console.log(`[@vitejs/plugin-legacy] modernTargets:`, modernTargets) - const getLegacyOutputFileName = ( fileNames: | string