Skip to content

Commit

Permalink
fix(css): always use css module content
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Jul 5, 2022
1 parent 0e6b82e commit f742645
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/vite/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ Repository: http://github.com/bripkens/connect-history-api-fallback.git

> The MIT License
>
> Copyright (c) 2012 Ben Ripkens http://bripkens.de
> Copyright (c) 2022 Ben Blackmore and contributors
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 5 additions & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,11 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
code = `export default ${JSON.stringify(content)}`
}
} else {
code = `export default ''`
// if moduleCode exists return it **even if** it does not have `?used`
// this will disable tree-shake to work with `import './foo.module.css'` but this usually does not happen
// this is a limitation of the current approach by `?used` to make tree-shake work
// See # for more details
code = modulesCode || `export default ''`
}

return {
Expand Down
9 changes: 4 additions & 5 deletions playground/css/__tests__/css.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ test('PostCSS dir-dependency', async () => {
}
})

// skip because #8278 is reverted
test.skip('import dependency includes css import', async () => {
test('import dependency includes css import', async () => {
expect(await getColor('.css-js-dep')).toBe('green')
expect(await getColor('.css-js-dep-module')).toBe('green')
})
Expand Down Expand Up @@ -437,9 +436,9 @@ test('PostCSS source.input.from includes query', async () => {
)
})

// skip because #8278 is reverted
test.skip('aliased css has content', async () => {
test('aliased css has content', async () => {
expect(await getColor('.aliased')).toBe('blue')
expect(await page.textContent('.aliased-content')).toMatch('.aliased')
// skipped: currently not supported see #
// expect(await page.textContent('.aliased-content')).toMatch('.aliased')
expect(await getColor('.aliased-module')).toBe('blue')
})

0 comments on commit f742645

Please sign in to comment.