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 =