Skip to content

Commit 72f17f8

Browse files
authored
fix(css): do not clean id when passing to postcss (fix #7822) (#7827)
1 parent d49e3fb commit 72f17f8

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,13 @@ test("relative path rewritten in Less's data-uri", async () => {
413413
/^url\("data:image\/svg\+xml,%3Csvg/
414414
)
415415
})
416+
417+
test('PostCSS source.input.from includes query', async () => {
418+
const code = await page.textContent('.postcss-source-input')
419+
// should resolve assets
420+
expect(code).toContain(
421+
isBuild
422+
? '/postcss-source-input.css?used&query=foo'
423+
: '/postcss-source-input.css?query=foo'
424+
)
425+
})

packages/playground/css/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ <h1>CSS</h1>
135135

136136
<p>Raw Support</p>
137137
<pre class="raw-imported-css"></pre>
138+
139+
<p>PostCSS source.input.from. Should include query</p>
140+
<pre class="postcss-source-input"></pre>
138141
</div>
139142

140143
<script type="module" src="./main.js"></script>

packages/playground/css/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,6 @@ Promise.all(Object.keys(glob).map((key) => glob[key]())).then((res) => {
8787
// globEager
8888
const globEager = import.meta.globEager('./glob-import/*.css')
8989
text('.imported-css-globEager', JSON.stringify(globEager, null, 2))
90+
91+
import postcssSourceInput from './postcss-source-input.css?query=foo'
92+
text('.postcss-source-input', postcssSourceInput)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@source-input;

packages/playground/css/postcss.config.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
plugins: [require('postcss-nested'), testDirDep]
2+
plugins: [require('postcss-nested'), testDirDep, testSourceInput]
33
}
44

55
const fs = require('fs')
@@ -35,3 +35,16 @@ function testDirDep() {
3535
}
3636
}
3737
testDirDep.postcss = true
38+
39+
function testSourceInput() {
40+
return {
41+
postcssPlugin: 'source-input',
42+
AtRule(atRule) {
43+
if (atRule.name === 'source-input') {
44+
atRule.after(`/* ${atRule.source.input.from} */`)
45+
atRule.remove()
46+
}
47+
}
48+
}
49+
}
50+
testSourceInput.postcss = true

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,8 @@ async function compileCSS(
799799
.default(postcssPlugins)
800800
.process(code, {
801801
...postcssOptions,
802-
to: cleanUrl(id),
803-
from: cleanUrl(id),
802+
to: id,
803+
from: id,
804804
map: {
805805
inline: false,
806806
annotation: false,

0 commit comments

Comments
 (0)