Skip to content

Commit c1d23a9

Browse files
ocavuesxzz
andauthored
fix(css): ignore css imports with URL query (#806)
Co-authored-by: Kevin Deng <sxzz@sxzz.moe>
1 parent f915b43 commit c1d23a9

File tree

7 files changed

+52
-2
lines changed

7 files changed

+52
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
"typescript": "catalog:dev",
176176
"unocss": "catalog:docs",
177177
"unplugin-ast": "catalog:dev",
178+
"unplugin-raw": "catalog:dev",
178179
"unplugin-unused": "catalog:peer",
179180
"unplugin-vue": "catalog:dev",
180181
"vite": "catalog:docs",

packages/css/src/preprocessors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function getPreprocessorLang(
2525
return PREPROCESSOR_LANGS[ext]
2626
}
2727

28-
const CSS_LANGS_RE = /\.(?:css|less|sass|scss|styl|stylus)(?:$|\?)/
28+
const CSS_LANGS_RE = /\.(?:css|less|sass|scss|styl|stylus)$/
2929

3030
export function isCssOrPreprocessor(filename: string): boolean {
3131
return CSS_LANGS_RE.test(filename)

pnpm-lock.yaml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ catalogs:
3535
sass: ^1.97.3
3636
typescript: ~5.9.3
3737
unplugin-ast: ^0.16.0
38+
unplugin-raw: ^0.6.4
3839
unplugin-vue: ^7.1.1
3940
vitest: ^4.0.18
4041
docs:

src/features/css/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createCssPostHooks, type CssStyles } from './post.ts'
22
import type { ResolvedConfig } from '../../config/index.ts'
33
import type { Plugin } from 'rolldown'
44

5-
export const RE_CSS: RegExp = /\.css(?:$|\?)/
5+
export const RE_CSS: RegExp = /\.css$/
66

77
export function getCleanId(id: string): string {
88
const queryIndex = id.indexOf('?')
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## index.mjs
2+
3+
```mjs
4+
//#endregion
5+
//#region index.ts
6+
console.log(".foo{color:red;}");
7+
//#endregion
8+
export {};
9+
10+
```

tests/css.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,24 @@ describe('css', () => {
351351
expect(fileMap['style.css']).not.toContain('should-not-appear')
352352
})
353353

354+
test('handle .css?raw with unplugin-raw', async (context) => {
355+
const raw = await import('unplugin-raw/rolldown')
356+
357+
const { fileMap, outputFiles } = await testBuild({
358+
context,
359+
files: {
360+
'index.ts': `import cssText from './foo.css?raw'; console.log(cssText);`,
361+
'foo.css': `.foo{color:red;}`,
362+
},
363+
options: {
364+
entry: ['index.ts'],
365+
plugins: [raw.default({})],
366+
},
367+
})
368+
expect(outputFiles).toEqual(['index.mjs'])
369+
expect(fileMap['index.mjs']).toContain(`.foo{color:red;}`)
370+
})
371+
354372
describe('@import bundling', () => {
355373
test('diamond dependency graph', async (context) => {
356374
// From esbuild TestCSSAtImport

0 commit comments

Comments
 (0)