Skip to content

Commit

Permalink
fix(css): do not clean id when passing to postcss (fix #7822) (#7827)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored May 4, 2022
1 parent d49e3fb commit 72f17f8
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/playground/css/__tests__/css.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,13 @@ test("relative path rewritten in Less's data-uri", async () => {
/^url\("data:image\/svg\+xml,%3Csvg/
)
})

test('PostCSS source.input.from includes query', async () => {
const code = await page.textContent('.postcss-source-input')
// should resolve assets
expect(code).toContain(
isBuild
? '/postcss-source-input.css?used&query=foo'
: '/postcss-source-input.css?query=foo'
)
})
3 changes: 3 additions & 0 deletions packages/playground/css/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ <h1>CSS</h1>

<p>Raw Support</p>
<pre class="raw-imported-css"></pre>

<p>PostCSS source.input.from. Should include query</p>
<pre class="postcss-source-input"></pre>
</div>

<script type="module" src="./main.js"></script>
3 changes: 3 additions & 0 deletions packages/playground/css/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ Promise.all(Object.keys(glob).map((key) => glob[key]())).then((res) => {
// globEager
const globEager = import.meta.globEager('./glob-import/*.css')
text('.imported-css-globEager', JSON.stringify(globEager, null, 2))

import postcssSourceInput from './postcss-source-input.css?query=foo'
text('.postcss-source-input', postcssSourceInput)
1 change: 1 addition & 0 deletions packages/playground/css/postcss-source-input.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@source-input;
15 changes: 14 additions & 1 deletion packages/playground/css/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
plugins: [require('postcss-nested'), testDirDep]
plugins: [require('postcss-nested'), testDirDep, testSourceInput]
}

const fs = require('fs')
Expand Down Expand Up @@ -35,3 +35,16 @@ function testDirDep() {
}
}
testDirDep.postcss = true

function testSourceInput() {
return {
postcssPlugin: 'source-input',
AtRule(atRule) {
if (atRule.name === 'source-input') {
atRule.after(`/* ${atRule.source.input.from} */`)
atRule.remove()
}
}
}
}
testSourceInput.postcss = true
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,8 @@ async function compileCSS(
.default(postcssPlugins)
.process(code, {
...postcssOptions,
to: cleanUrl(id),
from: cleanUrl(id),
to: id,
from: id,
map: {
inline: false,
annotation: false,
Expand Down

0 comments on commit 72f17f8

Please sign in to comment.