From 7f548e874a2fb2b09f08fe123bb3ebc10aa2f54b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Sat, 24 Sep 2022 00:29:58 +0900 Subject: [PATCH] fix(legacy): don't force set `build.target` when `renderLegacyChunks=false` (fixes #10201) (#10220) --- packages/plugin-legacy/src/index.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index 1e9850f8127b9f..203cad9dc293c6 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -176,17 +176,19 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { config.build.cssTarget = 'chrome61' } - // Vite's default target browsers are **not** the same. - // See https://github.com/vitejs/vite/pull/10052#issuecomment-1242076461 - overriddenBuildTarget = config.build.target !== undefined - // browsers supporting ESM + dynamic import + import.meta - config.build.target = [ - 'es2020', - 'edge79', - 'firefox67', - 'chrome64', - 'safari11.1' - ] + if (genLegacy) { + // Vite's default target browsers are **not** the same. + // See https://github.com/vitejs/vite/pull/10052#issuecomment-1242076461 + overriddenBuildTarget = config.build.target !== undefined + // browsers supporting ESM + dynamic import + import.meta + config.build.target = [ + 'es2020', + 'edge79', + 'firefox67', + 'chrome64', + 'safari11.1' + ] + } } return {