Skip to content

Commit 6092b8a

Browse files
committed
fix(plugins): skip virtual CSS injection for files without extracted CSS
Ensure virtual CSS is only imported when CSS is actually generated.
1 parent 98d2bc7 commit 6092b8a

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

packages/next/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const rawstyleTurboRule: Required<Required<NextConfig>['turbopack']>['rul
1111

1212
export default function (this: { resourcePath: string }, source: string): string {
1313
const { transformed, css } = transform(this.resourcePath, source)
14+
if (!css) return transformed
1415
const base64Css = Buffer.from(css, 'utf8').toString('base64')
1516
return `import 'data:text/css;base64,${base64Css}';${transformed}`
1617
}

packages/vite/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default (): Plugin => ({
2424
transform(code, id) {
2525
if (!TRANSFORMABLE_EXT.test(id)) return
2626
const { transformed, css } = transform(id, code)
27+
if (!css) return transformed
2728
const cssId = normalizePath(id + '.css')
2829
styles.set(cssId, css)
2930
return `import '${VIRTUAL_PREFIX}${cssId}';${transformed}`
@@ -33,6 +34,7 @@ export default (): Plugin => ({
3334
if (!TRANSFORMABLE_EXT.test(file)) return
3435
const sourceCode = await read()
3536
const { css } = transform(file, sourceCode)
37+
if (!css) return
3638
const cssId = normalizePath(file + '.css')
3739
const virtualId = RESOLVED_PREFIX + cssId
3840
const mod = server.moduleGraph.getModuleById(virtualId)

0 commit comments

Comments
 (0)