Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(css): do not clean id when passing to postcss (fix #7822) #7827

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/playground/css/__tests__/css.spec.ts
Expand Up @@ -405,3 +405,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'
sapphi-red marked this conversation as resolved.
Show resolved Hide resolved
: '/postcss-source-input.css?query=foo'
)
})
3 changes: 3 additions & 0 deletions packages/playground/css/index.html
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
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
@@ -0,0 +1 @@
@source-input;
15 changes: 14 additions & 1 deletion packages/playground/css/postcss.config.js
@@ -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
Expand Up @@ -785,8 +785,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