Skip to content

Commit 92125b4

Browse files
authored
fix(css): stabilize css module hashes with lightningcss in dev mode (#19481)
1 parent 644599d commit 92125b4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

+19
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,25 @@ composes: bar from '@/css/bar.module.css';
109109
const css = `\
110110
.foo {
111111
color: red;
112+
}`
113+
const result1 = await transform(css, '/foo.module.css') // server
114+
const result2 = await transform(css, '/foo.module.css?direct') // client
115+
expect(result1.code).toBe(result2.code)
116+
})
117+
118+
test('custom generateScopedName with lightningcss', async () => {
119+
const { transform } = await createCssPluginTransform({
120+
configFile: false,
121+
css: {
122+
modules: {
123+
generateScopedName: 'custom__[hash:base64:5]',
124+
},
125+
transformer: 'lightningcss',
126+
},
127+
})
128+
const css = `\
129+
.foo {
130+
color: red;
112131
}`
113132
const result1 = await transform(css, '/foo.module.css') // server
114133
const result2 = await transform(css, '/foo.module.css?direct') // client

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3298,7 +3298,7 @@ async function compileLightningCSS(
32983298
const deps = new Set<string>()
32993299
// replace null byte as lightningcss treats that as a string terminator
33003300
// https://github.com/parcel-bundler/lightningcss/issues/874
3301-
const filename = id.replace('\0', NULL_BYTE_PLACEHOLDER)
3301+
const filename = removeDirectQuery(id).replace('\0', NULL_BYTE_PLACEHOLDER)
33023302

33033303
let res: LightningCssTransformAttributeResult | LightningCssTransformResult
33043304
try {

0 commit comments

Comments
 (0)