From 1e0dee7e91aa1865f1df21bf0cccf8e4bc5b8bbb Mon Sep 17 00:00:00 2001 From: sapenlei <2503404258gl@gmail.com> Date: Sun, 29 Dec 2024 13:26:58 +0800 Subject: [PATCH] fix(plugin-legacy): avoid emitting the asset when renderLegacyChunks and renderModernChunk are both true (#18558) --- packages/plugin-legacy/src/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index d356793b231c72..6a86372ba30d73 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -532,11 +532,13 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { // entirely. opts.__vite_force_terser__ = true - // @ts-expect-error In the `generateBundle` hook, - // we'll delete the assets from the legacy bundle to avoid emitting duplicate assets. - // But that's still a waste of computing resource. - // So we add this flag to avoid emitting the asset in the first place whenever possible. - opts.__vite_skip_asset_emit__ = true + if (genModern) { + // @ts-expect-error In the `generateBundle` hook, + // we'll delete the assets from the legacy bundle to avoid emitting duplicate assets. + // But that's still a waste of computing resource. + // So we add this flag to avoid emitting the asset in the first place whenever possible. + opts.__vite_skip_asset_emit__ = true + } // avoid emitting assets for legacy bundle const needPolyfills =