From c0f3f81fa0f77eb885269f4cc25fc7bde18f8209 Mon Sep 17 00:00:00 2001 From: undermoon Date: Fri, 12 Jan 2024 21:37:18 +0800 Subject: [PATCH] feat(plugin-legacy): add `modernTargets` option warning --- packages/plugin-legacy/src/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index 1c34c88942d12b..c3caf3878f0c4a 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -185,6 +185,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { } let overriddenBuildTarget = false + let overriddenDefaultModernTargets = false const legacyConfigPlugin: Plugin = { name: 'vite:legacy-config', @@ -207,6 +208,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { // Vite's default target browsers are **not** the same. // See https://github.com/vitejs/vite/pull/10052#issuecomment-1242076461 overriddenBuildTarget = config.build.target !== undefined + overriddenDefaultModernTargets = options.modernTargets !== undefined config.build.target = options.modernTargets ? resolveToEsbuildTarget(browserslist(options.modernTargets)) : modernTargetsEsbuild @@ -230,6 +232,13 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { ), ) } + if (overriddenDefaultModernTargets) { + config.logger.warn( + colors.yellow( + `plugin-legacy overrode builtin targets of modern chunks. Some versions of browsers between legacy and modern maybe not be supported.`, + ), + ) + } }, }