Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: css codesplit inline problem #5750

Closed
wants to merge 2 commits into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
@@ -0,0 +1,3 @@
h3 {
color: yellow;
}
8 changes: 7 additions & 1 deletion packages/playground/css-codesplit/main.js
@@ -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
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