Skip to content

Commit

Permalink
fix: allow css to be written for systemjs output
Browse files Browse the repository at this point in the history
  • Loading branch information
shir0u committed May 10, 2022
1 parent 7b48e22 commit 485b600
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/vite/src/node/plugins/css.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions playground/legacy/package.json
Expand Up @@ -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"
},
Expand Down
39 changes: 39 additions & 0 deletions 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 `<script type="module">` tags and remove `nomodule`
// attrs so that we run the legacy bundle instead.
__test__() {
const indexPath = path.resolve(__dirname, './dist/index.html')
let index = fs.readFileSync(indexPath, 'utf-8')
index = index
.replace(/<script type="module".*?<\/script>/g, '')
.replace(/<script nomodule/g, '<script')
fs.writeFileSync(indexPath, index)
}
}

0 comments on commit 485b600

Please sign in to comment.