css-loader 6.9.0 → 6.10.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 +33 -18
- package/dist/utils.js +20 -6
- package/package.json +13 -4
package/README.md
CHANGED
|
@@ -605,12 +605,19 @@ module.exports = {
|
|
|
605
605
|
Type:
|
|
606
606
|
|
|
607
607
|
```ts
|
|
608
|
-
type auto =
|
|
608
|
+
type auto =
|
|
609
|
+
| boolean
|
|
610
|
+
| regExp
|
|
611
|
+
| ((
|
|
612
|
+
resourcePath: string,
|
|
613
|
+
resourceQuery: string,
|
|
614
|
+
resourceFragment: string
|
|
615
|
+
) => boolean);
|
|
609
616
|
```
|
|
610
617
|
|
|
611
618
|
Default: `undefined`
|
|
612
619
|
|
|
613
|
-
Allows auto enable CSS modules/ICSS based on filename when `modules` option is object.
|
|
620
|
+
Allows auto enable CSS modules/ICSS based on the filename, query or fragment when `modules` option is object.
|
|
614
621
|
|
|
615
622
|
Possible values:
|
|
616
623
|
|
|
@@ -673,7 +680,7 @@ module.exports = {
|
|
|
673
680
|
|
|
674
681
|
###### `function`
|
|
675
682
|
|
|
676
|
-
Enable CSS modules for files based on the filename satisfying your filter function check.
|
|
683
|
+
Enable CSS modules for files based on the filename, query or fragment satisfying your filter function check.
|
|
677
684
|
|
|
678
685
|
**webpack.config.js**
|
|
679
686
|
|
|
@@ -686,7 +693,9 @@ module.exports = {
|
|
|
686
693
|
loader: "css-loader",
|
|
687
694
|
options: {
|
|
688
695
|
modules: {
|
|
689
|
-
auto: (resourcePath) =>
|
|
696
|
+
auto: (resourcePath, resourceQuery, resourceFragment) => {
|
|
697
|
+
return resourcePath.endsWith(".custom-module.css");
|
|
698
|
+
},
|
|
690
699
|
},
|
|
691
700
|
},
|
|
692
701
|
},
|
|
@@ -705,7 +714,11 @@ type mode =
|
|
|
705
714
|
| "global"
|
|
706
715
|
| "pure"
|
|
707
716
|
| "icss"
|
|
708
|
-
| ((
|
|
717
|
+
| ((
|
|
718
|
+
resourcePath: string,
|
|
719
|
+
resourceQuery: string,
|
|
720
|
+
resourceFragment: string
|
|
721
|
+
) => "local" | "global" | "pure" | "icss");
|
|
709
722
|
```
|
|
710
723
|
|
|
711
724
|
Default: `'local'`
|
|
@@ -745,7 +758,7 @@ module.exports = {
|
|
|
745
758
|
|
|
746
759
|
###### `function`
|
|
747
760
|
|
|
748
|
-
Allows set different values for the `mode` option based on
|
|
761
|
+
Allows set different values for the `mode` option based on the filename, query or fragment.
|
|
749
762
|
|
|
750
763
|
Possible return values - `local`, `global`, `pure` and `icss`.
|
|
751
764
|
|
|
@@ -761,7 +774,7 @@ module.exports = {
|
|
|
761
774
|
options: {
|
|
762
775
|
modules: {
|
|
763
776
|
// Callback must return "local", "global", or "pure" values
|
|
764
|
-
mode: (resourcePath) => {
|
|
777
|
+
mode: (resourcePath, resourceQuery, resourceFragment) => {
|
|
765
778
|
if (/pure.css$/i.test(resourcePath)) {
|
|
766
779
|
return "pure";
|
|
767
780
|
}
|
|
@@ -1119,11 +1132,15 @@ Enables/disables ES modules named export for locals.
|
|
|
1119
1132
|
|
|
1120
1133
|
> **Warning**
|
|
1121
1134
|
>
|
|
1122
|
-
> Names of locals are converted to camelcase, i.e. the `exportLocalsConvention` option has
|
|
1135
|
+
> Names of locals are converted to camelcase, i.e. the `exportLocalsConvention` option has
|
|
1136
|
+
> `camelCaseOnly` value by default. You can set this back to any other valid option but selectors
|
|
1137
|
+
> which are not valid JavaScript identifiers may run into problems which do not implement the entire
|
|
1138
|
+
> modules specification.
|
|
1123
1139
|
|
|
1124
1140
|
> **Warning**
|
|
1125
1141
|
>
|
|
1126
|
-
> It is not allowed to use JavaScript reserved words in css class names
|
|
1142
|
+
> It is not allowed to use JavaScript reserved words in css class names unless
|
|
1143
|
+
> `exportLocalsConvention` is `"asIs"`.
|
|
1127
1144
|
|
|
1128
1145
|
**styles.css**
|
|
1129
1146
|
|
|
@@ -1139,9 +1156,11 @@ Enables/disables ES modules named export for locals.
|
|
|
1139
1156
|
**index.js**
|
|
1140
1157
|
|
|
1141
1158
|
```js
|
|
1142
|
-
import
|
|
1159
|
+
import * as styles from "./styles.css";
|
|
1143
1160
|
|
|
1144
|
-
console.log(fooBaz, bar);
|
|
1161
|
+
console.log(styles.fooBaz, styles.bar);
|
|
1162
|
+
// or if using `exportLocalsConvention: "asIs"`:
|
|
1163
|
+
console.log(styles["foo-baz"], styles.bar);
|
|
1145
1164
|
```
|
|
1146
1165
|
|
|
1147
1166
|
You can enable a ES module named export using:
|
|
@@ -1224,10 +1243,6 @@ Style of exported class names.
|
|
|
1224
1243
|
|
|
1225
1244
|
By default, the exported JSON keys mirror the class names (i.e `asIs` value).
|
|
1226
1245
|
|
|
1227
|
-
> **Warning**
|
|
1228
|
-
>
|
|
1229
|
-
> Only `camelCaseOnly` value allowed if you set the `namedExport` value to `true`.
|
|
1230
|
-
|
|
1231
1246
|
| Name | Type | Description |
|
|
1232
1247
|
| :-------------------: | :------: | :----------------------------------------------------------------------------------------------- |
|
|
1233
1248
|
| **`'asIs'`** | `string` | Class names will be exported as is. |
|
|
@@ -1534,7 +1549,7 @@ import "./styles.css";
|
|
|
1534
1549
|
|
|
1535
1550
|
> **Warning**
|
|
1536
1551
|
>
|
|
1537
|
-
> You
|
|
1552
|
+
> You should not use [`style-loader`](https://github.com/webpack-contrib/style-loader) or [`mini-css-extract-plugin`](https://github.com/webpack-contrib/mini-css-extract-plugin) with this value.
|
|
1538
1553
|
|
|
1539
1554
|
> **Warning**
|
|
1540
1555
|
>
|
|
@@ -1739,7 +1754,7 @@ With the help of the `/* webpackIgnore: true */`comment, it is possible to disab
|
|
|
1739
1754
|
.class {
|
|
1740
1755
|
/* Disabled url handling for the first url in the 'background' declaration */
|
|
1741
1756
|
color: red;
|
|
1742
|
-
background:
|
|
1757
|
+
background:
|
|
1743
1758
|
/* webpackIgnore: true */ url("./url/img.png"), url("./url/img.png");
|
|
1744
1759
|
}
|
|
1745
1760
|
|
|
@@ -1755,7 +1770,7 @@ With the help of the `/* webpackIgnore: true */`comment, it is possible to disab
|
|
|
1755
1770
|
/* Disabled url handling for the second url in the 'background' declaration */
|
|
1756
1771
|
color: red;
|
|
1757
1772
|
background: url("./url/img.png"),
|
|
1758
|
-
/* webpackIgnore: true */
|
|
1773
|
+
/* webpackIgnore: true */
|
|
1759
1774
|
url("./url/img.png");
|
|
1760
1775
|
}
|
|
1761
1776
|
|
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.10.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
|
-
"postcss": "^8.4.
|
|
59
|
+
"postcss": "^8.4.33",
|
|
51
60
|
"postcss-modules-extract-imports": "^3.0.0",
|
|
52
|
-
"postcss-modules-local-by-default": "^4.0.
|
|
53
|
-
"postcss-modules-scope": "^3.1.
|
|
61
|
+
"postcss-modules-local-by-default": "^4.0.4",
|
|
62
|
+
"postcss-modules-scope": "^3.1.1",
|
|
54
63
|
"postcss-modules-values": "^4.0.0",
|
|
55
64
|
"postcss-value-parser": "^4.2.0",
|
|
56
65
|
"semver": "^7.5.4"
|