Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { findAssetFile, getColor, isBuild, readManifest } from '../../testUtils'
test('should load both stylesheets', async () => {
expect(await getColor('h1')).toBe('red')
expect(await getColor('h2')).toBe('blue')
expect(await getColor('h3')).toBe('yellow')
})

if (isBuild) {
Expand Down
3 changes: 3 additions & 0 deletions packages/playground/css-codesplit/async.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h3 {
color: yellow;
}
8 changes: 7 additions & 1 deletion packages/playground/css-codesplit/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import './style.css'
import './main.css'
import('./async.css?inline').then((css) => {
const style = document.createElement('style')
style.dataset.import = true
style.textContent = css.default
document.head.appendChild(style)
})

document.getElementById(
'app'
).innerHTML = `<h1>This should be red</h1><h2>This should be blue</h2>`
).innerHTML = `<h1>This should be red</h1><h2>This should be blue</h2><h3>This should be yellow</h3>`
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
return {
code:
modulesCode ||
(usedRE.test(id)
(usedRE.test(id) || inlined
? `export default ${JSON.stringify(
inlined ? await minifyCSS(css, config) : css
)}`
Expand Down