Skip to content

Commit 6e0dd3a

Browse files
authoredJul 6, 2022
fix(css): always use css module content (#8936)
1 parent 339d9e3 commit 6e0dd3a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed
 

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,11 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
426426
code = `export default ${JSON.stringify(content)}`
427427
}
428428
} else {
429-
code = `export default ''`
429+
// if moduleCode exists return it **even if** it does not have `?used`
430+
// this will disable tree-shake to work with `import './foo.module.css'` but this usually does not happen
431+
// this is a limitation of the current approach by `?used` to make tree-shake work
432+
// See #8936 for more details
433+
code = modulesCode || `export default ''`
430434
}
431435

432436
return {

‎playground/css/__tests__/css.spec.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,7 @@ test('PostCSS dir-dependency', async () => {
349349
}
350350
})
351351

352-
// skip because #8278 is reverted
353-
test.skip('import dependency includes css import', async () => {
352+
test('import dependency includes css import', async () => {
354353
expect(await getColor('.css-js-dep')).toBe('green')
355354
expect(await getColor('.css-js-dep-module')).toBe('green')
356355
})
@@ -437,9 +436,9 @@ test('PostCSS source.input.from includes query', async () => {
437436
)
438437
})
439438

440-
// skip because #8278 is reverted
441-
test.skip('aliased css has content', async () => {
439+
test('aliased css has content', async () => {
442440
expect(await getColor('.aliased')).toBe('blue')
443-
expect(await page.textContent('.aliased-content')).toMatch('.aliased')
441+
// skipped: currently not supported see #8936
442+
// expect(await page.textContent('.aliased-content')).toMatch('.aliased')
444443
expect(await getColor('.aliased-module')).toBe('blue')
445444
})

0 commit comments

Comments
 (0)
Please sign in to comment.