css-loader 6.9.1 → 6.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -17
- package/dist/utils.js +20 -6
- package/package.json +13 -4
package/README.md
CHANGED
|
@@ -487,6 +487,15 @@ To import a local classname from another module.
|
|
|
487
487
|
|
|
488
488
|
To import from multiple modules use multiple `composes:` rules.
|
|
489
489
|
|
|
490
|
+
```css
|
|
491
|
+
:local(.className) {
|
|
492
|
+
composes: edit highlight from "./edit.css", button from "module/button.css", classFromThisModule;
|
|
493
|
+
background: red;
|
|
494
|
+
}
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
or
|
|
498
|
+
|
|
490
499
|
```css
|
|
491
500
|
:local(.className) {
|
|
492
501
|
composes: edit highlight from "./edit.css";
|
|
@@ -605,12 +614,19 @@ module.exports = {
|
|
|
605
614
|
Type:
|
|
606
615
|
|
|
607
616
|
```ts
|
|
608
|
-
type auto =
|
|
617
|
+
type auto =
|
|
618
|
+
| boolean
|
|
619
|
+
| regExp
|
|
620
|
+
| ((
|
|
621
|
+
resourcePath: string,
|
|
622
|
+
resourceQuery: string,
|
|
623
|
+
resourceFragment: string
|
|
624
|
+
) => boolean);
|
|
609
625
|
```
|
|
610
626
|
|
|
611
627
|
Default: `undefined`
|
|
612
628
|
|
|
613
|
-
Allows auto enable CSS modules/ICSS based on filename when `modules` option is object.
|
|
629
|
+
Allows auto enable CSS modules/ICSS based on the filename, query or fragment when `modules` option is object.
|
|
614
630
|
|
|
615
631
|
Possible values:
|
|
616
632
|
|
|
@@ -673,7 +689,7 @@ module.exports = {
|
|
|
673
689
|
|
|
674
690
|
###### `function`
|
|
675
691
|
|
|
676
|
-
Enable CSS modules for files based on the filename satisfying your filter function check.
|
|
692
|
+
Enable CSS modules for files based on the filename, query or fragment satisfying your filter function check.
|
|
677
693
|
|
|
678
694
|
**webpack.config.js**
|
|
679
695
|
|
|
@@ -686,7 +702,9 @@ module.exports = {
|
|
|
686
702
|
loader: "css-loader",
|
|
687
703
|
options: {
|
|
688
704
|
modules: {
|
|
689
|
-
auto: (resourcePath) =>
|
|
705
|
+
auto: (resourcePath, resourceQuery, resourceFragment) => {
|
|
706
|
+
return resourcePath.endsWith(".custom-module.css");
|
|
707
|
+
},
|
|
690
708
|
},
|
|
691
709
|
},
|
|
692
710
|
},
|
|
@@ -705,7 +723,11 @@ type mode =
|
|
|
705
723
|
| "global"
|
|
706
724
|
| "pure"
|
|
707
725
|
| "icss"
|
|
708
|
-
| ((
|
|
726
|
+
| ((
|
|
727
|
+
resourcePath: string,
|
|
728
|
+
resourceQuery: string,
|
|
729
|
+
resourceFragment: string
|
|
730
|
+
) => "local" | "global" | "pure" | "icss");
|
|
709
731
|
```
|
|
710
732
|
|
|
711
733
|
Default: `'local'`
|
|
@@ -745,7 +767,7 @@ module.exports = {
|
|
|
745
767
|
|
|
746
768
|
###### `function`
|
|
747
769
|
|
|
748
|
-
Allows set different values for the `mode` option based on
|
|
770
|
+
Allows set different values for the `mode` option based on the filename, query or fragment.
|
|
749
771
|
|
|
750
772
|
Possible return values - `local`, `global`, `pure` and `icss`.
|
|
751
773
|
|
|
@@ -761,7 +783,7 @@ module.exports = {
|
|
|
761
783
|
options: {
|
|
762
784
|
modules: {
|
|
763
785
|
// Callback must return "local", "global", or "pure" values
|
|
764
|
-
mode: (resourcePath) => {
|
|
786
|
+
mode: (resourcePath, resourceQuery, resourceFragment) => {
|
|
765
787
|
if (/pure.css$/i.test(resourcePath)) {
|
|
766
788
|
return "pure";
|
|
767
789
|
}
|
|
@@ -1119,11 +1141,15 @@ Enables/disables ES modules named export for locals.
|
|
|
1119
1141
|
|
|
1120
1142
|
> **Warning**
|
|
1121
1143
|
>
|
|
1122
|
-
> Names of locals are converted to camelcase, i.e. the `exportLocalsConvention` option has
|
|
1144
|
+
> Names of locals are converted to camelcase, i.e. the `exportLocalsConvention` option has
|
|
1145
|
+
> `camelCaseOnly` value by default. You can set this back to any other valid option but selectors
|
|
1146
|
+
> which are not valid JavaScript identifiers may run into problems which do not implement the entire
|
|
1147
|
+
> modules specification.
|
|
1123
1148
|
|
|
1124
1149
|
> **Warning**
|
|
1125
1150
|
>
|
|
1126
|
-
> It is not allowed to use JavaScript reserved words in css class names
|
|
1151
|
+
> It is not allowed to use JavaScript reserved words in css class names unless
|
|
1152
|
+
> `exportLocalsConvention` is `"asIs"`.
|
|
1127
1153
|
|
|
1128
1154
|
**styles.css**
|
|
1129
1155
|
|
|
@@ -1139,9 +1165,11 @@ Enables/disables ES modules named export for locals.
|
|
|
1139
1165
|
**index.js**
|
|
1140
1166
|
|
|
1141
1167
|
```js
|
|
1142
|
-
import
|
|
1168
|
+
import * as styles from "./styles.css";
|
|
1143
1169
|
|
|
1144
|
-
console.log(fooBaz, bar);
|
|
1170
|
+
console.log(styles.fooBaz, styles.bar);
|
|
1171
|
+
// or if using `exportLocalsConvention: "asIs"`:
|
|
1172
|
+
console.log(styles["foo-baz"], styles.bar);
|
|
1145
1173
|
```
|
|
1146
1174
|
|
|
1147
1175
|
You can enable a ES module named export using:
|
|
@@ -1224,10 +1252,6 @@ Style of exported class names.
|
|
|
1224
1252
|
|
|
1225
1253
|
By default, the exported JSON keys mirror the class names (i.e `asIs` value).
|
|
1226
1254
|
|
|
1227
|
-
> **Warning**
|
|
1228
|
-
>
|
|
1229
|
-
> Only `camelCaseOnly` value allowed if you set the `namedExport` value to `true`.
|
|
1230
|
-
|
|
1231
1255
|
| Name | Type | Description |
|
|
1232
1256
|
| :-------------------: | :------: | :----------------------------------------------------------------------------------------------- |
|
|
1233
1257
|
| **`'asIs'`** | `string` | Class names will be exported as is. |
|
|
@@ -1739,7 +1763,7 @@ With the help of the `/* webpackIgnore: true */`comment, it is possible to disab
|
|
|
1739
1763
|
.class {
|
|
1740
1764
|
/* Disabled url handling for the first url in the 'background' declaration */
|
|
1741
1765
|
color: red;
|
|
1742
|
-
background:
|
|
1766
|
+
background:
|
|
1743
1767
|
/* webpackIgnore: true */ url("./url/img.png"), url("./url/img.png");
|
|
1744
1768
|
}
|
|
1745
1769
|
|
|
@@ -1755,7 +1779,7 @@ With the help of the `/* webpackIgnore: true */`comment, it is possible to disab
|
|
|
1755
1779
|
/* Disabled url handling for the second url in the 'background' declaration */
|
|
1756
1780
|
color: red;
|
|
1757
1781
|
background: url("./url/img.png"),
|
|
1758
|
-
/* webpackIgnore: true */
|
|
1782
|
+
/* webpackIgnore: true */
|
|
1759
1783
|
url("./url/img.png");
|
|
1760
1784
|
}
|
|
1761
1785
|
|
package/dist/utils.js
CHANGED
|
@@ -487,7 +487,8 @@ function getModulesOptions(rawOptions, exportType, loaderContext) {
|
|
|
487
487
|
namedExport: needNamedExport || false,
|
|
488
488
|
exportLocalsConvention: (rawModulesOptions.namedExport === true || needNamedExport) && typeof rawModulesOptions.exportLocalsConvention === "undefined" ? "camelCaseOnly" : "asIs",
|
|
489
489
|
exportOnlyLocals: false,
|
|
490
|
-
...rawModulesOptions
|
|
490
|
+
...rawModulesOptions,
|
|
491
|
+
useExportsAs: rawModulesOptions.exportLocalsConvention === "asIs"
|
|
491
492
|
};
|
|
492
493
|
let exportLocalsConventionType;
|
|
493
494
|
if (typeof modulesOptions.exportLocalsConvention === "string") {
|
|
@@ -534,13 +535,17 @@ function getModulesOptions(rawOptions, exportType, loaderContext) {
|
|
|
534
535
|
return false;
|
|
535
536
|
}
|
|
536
537
|
} else if (typeof modulesOptions.auto === "function") {
|
|
537
|
-
const
|
|
538
|
+
const {
|
|
539
|
+
resourceQuery,
|
|
540
|
+
resourceFragment
|
|
541
|
+
} = loaderContext;
|
|
542
|
+
const isModule = modulesOptions.auto(resourcePath, resourceQuery, resourceFragment);
|
|
538
543
|
if (!isModule) {
|
|
539
544
|
return false;
|
|
540
545
|
}
|
|
541
546
|
}
|
|
542
547
|
if (typeof modulesOptions.mode === "function") {
|
|
543
|
-
modulesOptions.mode = modulesOptions.mode(loaderContext.resourcePath);
|
|
548
|
+
modulesOptions.mode = modulesOptions.mode(loaderContext.resourcePath, loaderContext.resourceQuery, loaderContext.resourceFragment);
|
|
544
549
|
}
|
|
545
550
|
if (needNamedExport) {
|
|
546
551
|
if (rawOptions.esModule === false) {
|
|
@@ -554,7 +559,7 @@ function getModulesOptions(rawOptions, exportType, loaderContext) {
|
|
|
554
559
|
if (rawOptions.esModule === false) {
|
|
555
560
|
throw new Error("The 'modules.namedExport' option requires the 'esModule' option to be enabled");
|
|
556
561
|
}
|
|
557
|
-
if (typeof exportLocalsConventionType === "string" && exportLocalsConventionType !== "camelCaseOnly" && exportLocalsConventionType !== "dashesOnly") {
|
|
562
|
+
if (typeof exportLocalsConventionType === "string" && exportLocalsConventionType !== "asIs" && exportLocalsConventionType !== "camelCaseOnly" && exportLocalsConventionType !== "dashesOnly") {
|
|
558
563
|
throw new Error('The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "camelCaseOnly" or "dashesOnly"');
|
|
559
564
|
}
|
|
560
565
|
}
|
|
@@ -868,16 +873,25 @@ function getExportCode(exports, replacements, icssPluginUsed, options, isTemplat
|
|
|
868
873
|
let code = "// Exports\n";
|
|
869
874
|
if (icssPluginUsed) {
|
|
870
875
|
let localsCode = "";
|
|
876
|
+
let identifierId = 0;
|
|
871
877
|
const addExportToLocalsCode = (names, value) => {
|
|
872
878
|
const normalizedNames = Array.isArray(names) ? new Set(names) : new Set([names]);
|
|
873
879
|
for (const name of normalizedNames) {
|
|
880
|
+
const serializedValue = isTemplateLiteralSupported ? convertToTemplateLiteral(value) : JSON.stringify(value);
|
|
874
881
|
if (options.modules.namedExport) {
|
|
875
|
-
|
|
882
|
+
if (options.modules.useExportsAs) {
|
|
883
|
+
identifierId += 1;
|
|
884
|
+
const id = `_${identifierId.toString(16)}`;
|
|
885
|
+
localsCode += `var ${id} = ${serializedValue};\n`;
|
|
886
|
+
localsCode += `export { ${id} as ${JSON.stringify(name)} };\n`;
|
|
887
|
+
} else {
|
|
888
|
+
localsCode += `export var ${name} = ${serializedValue};\n`;
|
|
889
|
+
}
|
|
876
890
|
} else {
|
|
877
891
|
if (localsCode) {
|
|
878
892
|
localsCode += `,\n`;
|
|
879
893
|
}
|
|
880
|
-
localsCode += `\t${JSON.stringify(name)}: ${
|
|
894
|
+
localsCode += `\t${JSON.stringify(name)}: ${serializedValue}`;
|
|
881
895
|
}
|
|
882
896
|
}
|
|
883
897
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-loader",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.11.0",
|
|
4
4
|
"description": "css loader module for webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "webpack-contrib/css-loader",
|
|
@@ -43,14 +43,23 @@
|
|
|
43
43
|
"dist"
|
|
44
44
|
],
|
|
45
45
|
"peerDependencies": {
|
|
46
|
+
"@rspack/core": "0.x || 1.x",
|
|
46
47
|
"webpack": "^5.0.0"
|
|
47
48
|
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"@rspack/core": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"webpack": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
48
57
|
"dependencies": {
|
|
49
58
|
"icss-utils": "^5.1.0",
|
|
50
59
|
"postcss": "^8.4.33",
|
|
51
|
-
"postcss-modules-extract-imports": "^3.
|
|
52
|
-
"postcss-modules-local-by-default": "^4.0.
|
|
53
|
-
"postcss-modules-scope": "^3.
|
|
60
|
+
"postcss-modules-extract-imports": "^3.1.0",
|
|
61
|
+
"postcss-modules-local-by-default": "^4.0.5",
|
|
62
|
+
"postcss-modules-scope": "^3.2.0",
|
|
54
63
|
"postcss-modules-values": "^4.0.0",
|
|
55
64
|
"postcss-value-parser": "^4.2.0",
|
|
56
65
|
"semver": "^7.5.4"
|