Skip to content

Commit 2d13902

Browse files
committed
chore: add resourceQuery
1 parent 63d4038 commit 2d13902

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

packages/core/src/css/cssConfig.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ export function isCssFile(filepath: string): boolean {
2323
}
2424

2525
const CSS_MODULE_REG = /\.module\.\w+$/i;
26+
27+
/**
28+
* This function is modified based on
29+
* https://github.com/web-infra-dev/rspack/blob/7b80a45a1c58de7bc506dbb107fad6fda37d2a1f/packages/rspack/src/loader-runner/index.ts#L903
30+
*/
31+
const PATH_QUERY_FRAGMENT_REGEXP =
32+
/^((?:\u200b.|[^?#\u200b])*)(\?(?:\u200b.|[^#\u200b])*)?(#.*)?$/;
33+
export function parsePathQueryFragment(str: string): {
34+
path: string;
35+
query: string;
36+
fragment: string;
37+
} {
38+
const match = PATH_QUERY_FRAGMENT_REGEXP.exec(str);
39+
return {
40+
path: match?.[1]?.replace(/\u200b(.)/g, '$1') || '',
41+
query: match?.[2] ? match[2].replace(/\u200b(.)/g, '$1') : '',
42+
fragment: match?.[3] || '',
43+
};
44+
}
45+
2646
export function isCssModulesFile(
2747
filepath: string,
2848
auto: CssLoaderOptionsAuto,
@@ -37,7 +57,9 @@ export function isCssModulesFile(
3757
}
3858

3959
if (typeof auto === 'function') {
40-
return auto(filepath, '', '');
60+
const { path, query, fragment } = parsePathQueryFragment(filepath);
61+
// this is a mock for loader
62+
return auto(path, query, fragment);
4163
}
4264

4365
return false;

0 commit comments

Comments
 (0)