Skip to content

Commit 84ec02a

Browse files
authored
fix(css): backport #8936 (#8977)
1 parent 194a265 commit 84ec02a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/playground/css/__tests__/css.spec.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ test('PostCSS dir-dependency', async () => {
342342
}
343343
})
344344

345-
// skip because #8471 is reverted
346-
test.skip('import dependency includes css import', async () => {
345+
test('import dependency includes css import', async () => {
347346
expect(await getColor('.css-js-dep')).toBe('green')
348347
expect(await getColor('.css-js-dep-module')).toBe('green')
349348
})
@@ -430,9 +429,9 @@ test('PostCSS source.input.from includes query', async () => {
430429
)
431430
})
432431

433-
// skip because #8471 is reverted
434-
test.skip('aliased css has content', async () => {
432+
test('aliased css has content', async () => {
435433
expect(await getColor('.aliased')).toBe('blue')
436-
expect(await page.textContent('.aliased-content')).toMatch('.aliased')
434+
// skipped: currently not supported see #8936
435+
// expect(await page.textContent('.aliased-content')).toMatch('.aliased')
437436
expect(await getColor('.aliased-module')).toBe('blue')
438437
})

packages/vite/src/node/plugins/css.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,11 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
381381
code = `export default ${JSON.stringify(content)}`
382382
}
383383
} else {
384-
code = `export default ''`
384+
// if moduleCode exists return it **even if** it does not have `?used`
385+
// this will disable tree-shake to work with `import './foo.module.css'` but this usually does not happen
386+
// this is a limitation of the current approach by `?used` to make tree-shake work
387+
// See #8936 for more details
388+
code = modulesCode || `export default ''`
385389
}
386390

387391
return {

0 commit comments

Comments
 (0)