From 485b600ce23727f0b5d7b8514b52c0e0e62f185d Mon Sep 17 00:00:00 2001 From: shir0u <85612853+shir0u@users.noreply.github.com> Date: Tue, 2 Nov 2021 03:59:37 +1100 Subject: [PATCH] fix: allow css to be written for systemjs output --- packages/vite/src/node/plugins/css.ts | 8 +++- playground/legacy/package.json | 1 + playground/legacy/vite.config-dynamic-css.js | 39 ++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 playground/legacy/vite.config-dynamic-css.js diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 3ffd93bb9f9910..68bda09e96ef1a 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -452,7 +452,11 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { // this is a shared CSS-only chunk that is empty. pureCssChunks.add(chunk.fileName) } - if (opts.format === 'es' || opts.format === 'cjs') { + if ( + opts.format === 'es' || + opts.format === 'cjs' || + opts.format === 'system' + ) { chunkCSS = await processChunkCSS(chunkCSS, { inlined: false, minify: true @@ -513,7 +517,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { .join('|') .replace(/\./g, '\\.') const emptyChunkRE = new RegExp( - opts.format === 'es' + opts.format === 'es' || opts.format === 'system' ? `\\bimport\\s*"[^"]*(?:${emptyChunkFiles})";\n?` : `\\brequire\\(\\s*"[^"]*(?:${emptyChunkFiles})"\\);\n?`, 'g' diff --git a/playground/legacy/package.json b/playground/legacy/package.json index f8803564f93f12..4f11c234573f40 100644 --- a/playground/legacy/package.json +++ b/playground/legacy/package.json @@ -6,6 +6,7 @@ "dev": "vite", "build": "vite build --debug legacy", "build:custom-filename": "vite --config ./vite.config-custom-filename.js build --debug legacy", + "build:dynamic-css": "vite --config ./vite.config-dynamic-css.js build --debug legacy", "debug": "node --inspect-brk ../../packages/vite/bin/vite", "preview": "vite preview" }, diff --git a/playground/legacy/vite.config-dynamic-css.js b/playground/legacy/vite.config-dynamic-css.js new file mode 100644 index 00000000000000..10565768ac4d49 --- /dev/null +++ b/playground/legacy/vite.config-dynamic-css.js @@ -0,0 +1,39 @@ +const fs = require('fs') +const path = require('path') +const legacy = require('@vitejs/plugin-legacy').default + +module.exports = { + plugins: [ + legacy({ + targets: 'IE 11' + }) + ], + + build: { + cssCodeSplit: true, + manifest: true, + rollupOptions: { + output: { + chunkFileNames(chunkInfo) { + if (chunkInfo.name === 'immutable-chunk') { + return `assets/${chunkInfo.name}.js` + } + + return `assets/chunk-[name].[hash].js` + } + } + } + }, + + // special test only hook + // for tests, remove `