From db125a706748cd3182d32077fad38b3c809b1010 Mon Sep 17 00:00:00 2001 From: armano Date: Fri, 8 Mar 2024 21:48:11 +0100 Subject: [PATCH] fix(legacy): emit css assets when no cssCodeSplit and modernChuns are off --- packages/plugin-legacy/src/index.ts | 2 +- playground/legacy/package.json | 1 + .../legacy/vite.config-css-code-split.js | 21 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 playground/legacy/vite.config-css-code-split.js diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index c33893420c8ed0..0958fa8880bf12 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -467,7 +467,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { // 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 + opts.__vite_skip_asset_emit__ = genModern // avoid emitting assets for legacy bundle const needPolyfills = diff --git a/playground/legacy/package.json b/playground/legacy/package.json index 2a69750a84af84..01bfdba27d09e7 100644 --- a/playground/legacy/package.json +++ b/playground/legacy/package.json @@ -10,6 +10,7 @@ "build:multiple-output": "vite --config ./vite.config-multiple-output.js build", "build:no-polyfills": "vite --config ./vite.config-no-polyfills.js build", "build:no-polyfills-no-systemjs": "vite --config ./vite.config-no-polyfills-no-systemjs.js build", + "build:css-code-split": "vite --config ./vite.config-css-code-split.js build", "build:watch": "vite --config ./vite.config-watch.js build --debug legacy", "debug": "node --inspect-brk ../../packages/vite/bin/vite", "preview": "vite preview" diff --git a/playground/legacy/vite.config-css-code-split.js b/playground/legacy/vite.config-css-code-split.js new file mode 100644 index 00000000000000..9c5c46ef756cc4 --- /dev/null +++ b/playground/legacy/vite.config-css-code-split.js @@ -0,0 +1,21 @@ +import path from 'node:path' +import legacy from '@vitejs/plugin-legacy' +import { defineConfig } from 'vite' + +export default defineConfig({ + plugins: [ + legacy({ + renderModernChunks: false, + }), + ], + + build: { + outDir: 'dist/css-code-split', + cssCodeSplit: false, + rollupOptions: { + input: { + index: path.resolve(__dirname, 'index.html'), + }, + }, + }, +})