css-loader 6.6.0 → 6.7.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 CHANGED
@@ -29,6 +29,18 @@ To begin, you'll need to install `css-loader`:
29
29
  npm install --save-dev css-loader
30
30
  ```
31
31
 
32
+ or
33
+
34
+ ```console
35
+ yarn add -D css-loader
36
+ ```
37
+
38
+ or
39
+
40
+ ```console
41
+ pnpm add -D css-loader
42
+ ```
43
+
32
44
  Then add the plugin to your `webpack` config. For example:
33
45
 
34
46
  **file.js**
@@ -58,19 +70,26 @@ If, for one reason or another, you need to extract CSS as a file (i.e. do not st
58
70
 
59
71
  ## Options
60
72
 
61
- | Name | Type | Default | Description |
62
- | :-----------------------------------: | :------------------------------------------: | :----------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
63
- | **[`url`](#url)** | `{Boolean\|Object}` | `true` | Allows to enables/disables `url()`/`image-set()` functions handling |
64
- | **[`import`](#import)** | `{Boolean\|Object}` | `true` | Allows to enables/disables `@import` at-rules handling |
65
- | **[`modules`](#modules)** | `{Boolean\|String\|Object}` | `{auto: true}` | Allows to enables/disables or setup CSS Modules options |
66
- | **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps |
67
- | **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Allows enables/disables or setups number of loaders applied before CSS loader for `@import`/CSS Modules and ICSS imports |
68
- | **[`esModule`](#esmodule)** | `{Boolean}` | `true` | Use ES modules syntax |
69
- | **[`exportType`](#exporttype)** | `{'array' \| 'string' \| 'css-style-sheet'}` | `array` | Allows exporting styles as array with modules, string or [constructable stylesheet](https://developers.google.com/web/updates/2019/02/constructable-stylesheets) (i.e. [`CSSStyleSheet`](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet)) |
73
+ - **[`url`](#url)**
74
+ - **[`import`](#import)**
75
+ - **[`modules`](#modules)**
76
+ - **[`sourceMap`](#sourcemap)**
77
+ - **[`importLoaders`](#importloaders)**
78
+ - **[`esModule`](#esmodule)**
79
+ - **[`exportType`](#exporttype)**
70
80
 
71
81
  ### `url`
72
82
 
73
- Type: `Boolean|Object`
83
+ Type:
84
+
85
+ ```ts
86
+ type url =
87
+ | boolean
88
+ | {
89
+ url: (url: string, resourcePath: string) => boolean;
90
+ };
91
+ ```
92
+
74
93
  Default: `true`
75
94
 
76
95
  Allow to enable/disables handling the CSS functions `url` and `image-set`.
@@ -80,7 +99,7 @@ Starting with version [4.0.0](https://github.com/webpack-contrib/css-loader/blob
80
99
 
81
100
  Examples resolutions:
82
101
 
83
- ```
102
+ ```js
84
103
  url(image.png) => require('./image.png')
85
104
  url('image.png') => require('./image.png')
86
105
  url(./image.png) => require('./image.png')
@@ -91,13 +110,13 @@ image-set(url('image2x.png') 1x, url('image1x.png') 2x) => require('./image1x.pn
91
110
 
92
111
  To import assets from a `node_modules` path (include `resolve.modules`) and for `alias`, prefix it with a `~`:
93
112
 
94
- ```
113
+ ```js
95
114
  url(~module/image.png) => require('module/image.png')
96
115
  url('~module/image.png') => require('module/image.png')
97
116
  url(~aliasDirectory/image.png) => require('otherDirectory/image.png')
98
117
  ```
99
118
 
100
- #### `Boolean`
119
+ #### `boolean`
101
120
 
102
121
  Enable/disable `url()` resolving.
103
122
 
@@ -119,7 +138,7 @@ module.exports = {
119
138
  };
120
139
  ```
121
140
 
122
- #### `Object`
141
+ #### `object`
123
142
 
124
143
  Allow to filter `url()`. All filtered `url()` will not be resolved (left in the code as they were written).
125
144
 
@@ -154,7 +173,16 @@ module.exports = {
154
173
 
155
174
  ### `import`
156
175
 
157
- Type: `Boolean|Object`
176
+ Type:
177
+
178
+ <!-- use other name to prettify since import is reserved keyword -->
179
+
180
+ ```ts
181
+ type import =
182
+ | boolean
183
+ | { filter: (url: string, media: string, resourcePath: string) => boolean };
184
+ ```
185
+
158
186
  Default: `true`
159
187
 
160
188
  Allows to enables/disables `@import` at-rules handling.
@@ -180,7 +208,7 @@ To import styles from a `node_modules` path (include `resolve.modules`) and for
180
208
  @import url(~aliasDirectory/style.css) => require('otherDirectory/style.css')
181
209
  ```
182
210
 
183
- #### `Boolean`
211
+ #### `boolean`
184
212
 
185
213
  Enable/disable `@import` resolving.
186
214
 
@@ -202,15 +230,16 @@ module.exports = {
202
230
  };
203
231
  ```
204
232
 
205
- #### `Object`
206
-
207
- | Name | Type | Default | Description |
208
- | :---------------------: | :----------: | :---------: | :------------------------ |
209
- | **[`filter`](#filter)** | `{Function}` | `undefined` | Allow to filter `@import` |
233
+ #### `object`
210
234
 
211
235
  ##### `filter`
212
236
 
213
- Type: `Function`
237
+ Type:
238
+
239
+ ```ts
240
+ type filter = (url: string, media: string, resourcePath: string) => boolean;
241
+ ```
242
+
214
243
  Default: `undefined`
215
244
 
216
245
  Allow to filter `@import`. All filtered `@import` will not be resolved (left in the code as they were written).
@@ -246,7 +275,47 @@ module.exports = {
246
275
 
247
276
  ### `modules`
248
277
 
249
- Type: `Boolean|String|Object`
278
+ Type:
279
+
280
+ ```ts
281
+ type modules =
282
+ | boolean
283
+ | "local"
284
+ | "global"
285
+ | "pure"
286
+ | "icss"
287
+ | {
288
+ auto: boolean | regExp | ((resourcePath: string) => boolean);
289
+ mode:
290
+ | "local"
291
+ | "global"
292
+ | "pure"
293
+ | "icss"
294
+ | ((resourcePath) => "local" | "global" | "pure" | "icss");
295
+ localIdentName: string;
296
+ localIdentContext: string;
297
+ localIdentHashSalt: string;
298
+ localIdentHashFunction: string;
299
+ localIdentHashDigest: string;
300
+ localIdentRegExp: string | regExp;
301
+ getLocalIdent: (
302
+ context: LoaderContext,
303
+ localIdentName: string,
304
+ localName: string
305
+ ) => string;
306
+ namedExport: boolean;
307
+ exportGlobals: boolean;
308
+ exportLocalsConvention:
309
+ | "asIs"
310
+ | "camelCase"
311
+ | "camelCaseOnly"
312
+ | "dashes"
313
+ | "dashesOnly"
314
+ | ((name: string) => string);
315
+ exportOnlyLocals: boolean;
316
+ };
317
+ ```
318
+
250
319
  Default: `undefined`
251
320
 
252
321
  Allows to enable/disable CSS Modules or ICSS and setup configuration:
@@ -436,7 +505,7 @@ We recommend use prefix `v-` for values, `s-` for selectors and `m-` for media a
436
505
  }
437
506
  ```
438
507
 
439
- #### `Boolean`
508
+ #### `boolean`
440
509
 
441
510
  Enable **CSS Modules** features.
442
511
 
@@ -458,7 +527,7 @@ module.exports = {
458
527
  };
459
528
  ```
460
529
 
461
- #### `String`
530
+ #### `string`
462
531
 
463
532
  Enable **CSS Modules** features and setup `mode`.
464
533
 
@@ -481,7 +550,7 @@ module.exports = {
481
550
  };
482
551
  ```
483
552
 
484
- #### `Object`
553
+ #### `object`
485
554
 
486
555
  Enable **CSS Modules** features and setup options for them.
487
556
 
@@ -515,7 +584,12 @@ module.exports = {
515
584
 
516
585
  ##### `auto`
517
586
 
518
- Type: `Boolean|RegExp|Function`
587
+ Type:
588
+
589
+ ```ts
590
+ type auto = boolean | regExp | ((resourcePath: string) => boolean);
591
+ ```
592
+
519
593
  Default: `undefined`
520
594
 
521
595
  Allows auto enable CSS modules/ICSS based on filename when `modules` option is object.
@@ -528,7 +602,7 @@ Possible values:
528
602
  - `RegExp` - enable CSS modules for all files matching `/RegExp/i.test(filename)` regexp.
529
603
  - `function` - enable CSS Modules for files based on the filename satisfying your filter function check.
530
604
 
531
- ###### `Boolean`
605
+ ###### `boolean`
532
606
 
533
607
  Possible values:
534
608
 
@@ -579,7 +653,7 @@ module.exports = {
579
653
  };
580
654
  ```
581
655
 
582
- ###### `Function`
656
+ ###### `function`
583
657
 
584
658
  Enable css modules for files based on the filename satisfying your filter function check.
585
659
 
@@ -605,7 +679,17 @@ module.exports = {
605
679
 
606
680
  ##### `mode`
607
681
 
608
- Type: `String|Function`
682
+ Type:
683
+
684
+ ```ts
685
+ type mode =
686
+ | "local"
687
+ | "global"
688
+ | "pure"
689
+ | "icss"
690
+ | ((resourcePath) => "local" | "global" | "pure" | "icss"))`
691
+ ```
692
+
609
693
  Default: `'local'`
610
694
 
611
695
  Setup `mode` option. You can omit the value when you want `local` mode.
@@ -617,7 +701,7 @@ The `icss` will only compile the low level `Interoperable CSS` format for declar
617
701
 
618
702
  ICSS underpins CSS Module support, and provides a low level syntax for other tools to implement CSS-module variations of their own.
619
703
 
620
- ###### `String`
704
+ ###### `string`
621
705
 
622
706
  Possible values - `local`, `global`, `pure`, and `icss`.
623
707
 
@@ -641,7 +725,7 @@ module.exports = {
641
725
  };
642
726
  ```
643
727
 
644
- ###### `Function`
728
+ ###### `function`
645
729
 
646
730
  Allows set different values for the `mode` option based on a filename
647
731
 
@@ -680,7 +764,12 @@ module.exports = {
680
764
 
681
765
  ##### `localIdentName`
682
766
 
683
- Type: `String`
767
+ Type:
768
+
769
+ ```ts
770
+ type localIdentName = string;
771
+ ```
772
+
684
773
  Default: `'[hash:base64]'`
685
774
 
686
775
  Allows to configure the generated local ident name.
@@ -735,7 +824,12 @@ module.exports = {
735
824
 
736
825
  ##### `localIdentContext`
737
826
 
738
- Type: `String`
827
+ Type:
828
+
829
+ ```ts
830
+ type localIdentContex = string;
831
+ ```
832
+
739
833
  Default: `compiler.context`
740
834
 
741
835
  Allows to redefine basic loader context for local ident name.
@@ -762,7 +856,12 @@ module.exports = {
762
856
 
763
857
  ##### `localIdentHashSalt`
764
858
 
765
- Type: `String`
859
+ Type:
860
+
861
+ ```ts
862
+ type localIdentHashSalt = string;
863
+ ```
864
+
766
865
  Default: `undefined`
767
866
 
768
867
  Allows to add custom hash to generate more unique classes.
@@ -790,7 +889,12 @@ module.exports = {
790
889
 
791
890
  ##### `localIdentHashFunction`
792
891
 
793
- Type: `String`
892
+ Type:
893
+
894
+ ```ts
895
+ type localIdentHashFunction = string;
896
+ ```
897
+
794
898
  Default: `md4`
795
899
 
796
900
  Allows to specify hash function to generate classes .
@@ -818,7 +922,12 @@ module.exports = {
818
922
 
819
923
  ##### `localIdentHashDigest`
820
924
 
821
- Type: `String`
925
+ Type:
926
+
927
+ ```ts
928
+ type localIdentHashDigest = string;
929
+ ```
930
+
822
931
  Default: `hex`
823
932
 
824
933
  Allows to specify hash digest to generate classes.
@@ -846,7 +955,12 @@ module.exports = {
846
955
 
847
956
  ##### `localIdentHashDigestLength`
848
957
 
849
- Type: `Number`
958
+ Type:
959
+
960
+ ```ts
961
+ type localIdentHashDigestLength = number;
962
+ ```
963
+
850
964
  Default: `20`
851
965
 
852
966
  Allows to specify hash digest length to generate classes.
@@ -904,7 +1018,12 @@ module.exports = {
904
1018
 
905
1019
  ##### `localIdentRegExp`
906
1020
 
907
- Type: `String|RegExp`
1021
+ Type:
1022
+
1023
+ ```ts
1024
+ type localIdentRegExp = string | RegExp;
1025
+ ```
1026
+
908
1027
  Default: `undefined`
909
1028
 
910
1029
  **webpack.config.js**
@@ -929,7 +1048,16 @@ module.exports = {
929
1048
 
930
1049
  ##### `getLocalIdent`
931
1050
 
932
- Type: `Function`
1051
+ Type:
1052
+
1053
+ ```ts
1054
+ type getLocalIdent = (
1055
+ context: LoaderContext,
1056
+ localIdentName: string,
1057
+ localName: string
1058
+ ) => string;
1059
+ ```
1060
+
933
1061
  Default: `undefined`
934
1062
 
935
1063
  Allows to specify a function to generate the classname.
@@ -961,7 +1089,12 @@ module.exports = {
961
1089
 
962
1090
  ##### `namedExport`
963
1091
 
964
- Type: `Boolean`
1092
+ Type:
1093
+
1094
+ ```ts
1095
+ type namedExport = boolean;
1096
+ ```
1097
+
965
1098
  Default: `false`
966
1099
 
967
1100
  Enables/disables ES modules named export for locals.
@@ -1017,7 +1150,12 @@ Example below in the [`examples`](#examples) section.
1017
1150
 
1018
1151
  ##### `exportGlobals`
1019
1152
 
1020
- Type: `Boolean`
1153
+ Type:
1154
+
1155
+ ```ts
1156
+ type exportsGLobals = boolean;
1157
+ ```
1158
+
1021
1159
  Default: `false`
1022
1160
 
1023
1161
  Allow `css-loader` to export names from global class or id, so you can use that as local name.
@@ -1044,24 +1182,35 @@ module.exports = {
1044
1182
 
1045
1183
  ##### `exportLocalsConvention`
1046
1184
 
1047
- Type: `String|Function`
1185
+ Type:
1186
+
1187
+ ```ts
1188
+ type exportLocalsConvention =
1189
+ | "asIs"
1190
+ | "camelCase"
1191
+ | "camelCaseOnly"
1192
+ | "dashes"
1193
+ | "dashesOnly"
1194
+ | ((name: string) => string);
1195
+ ```
1196
+
1048
1197
  Default: based on the `modules.namedExport` option value, if `true` - `camelCaseOnly`, otherwise `asIs`
1049
1198
 
1050
1199
  Style of exported class names.
1051
1200
 
1052
- ###### `String`
1201
+ ###### `string`
1053
1202
 
1054
1203
  By default, the exported JSON keys mirror the class names (i.e `asIs` value).
1055
1204
 
1056
1205
  > ⚠ Only `camelCaseOnly` value allowed if you set the `namedExport` value to `true`.
1057
1206
 
1058
- | Name | Type | Description |
1059
- | :-------------------: | :--------: | :----------------------------------------------------------------------------------------------- |
1060
- | **`'asIs'`** | `{String}` | Class names will be exported as is. |
1061
- | **`'camelCase'`** | `{String}` | Class names will be camelized, the original class name will not to be removed from the locals |
1062
- | **`'camelCaseOnly'`** | `{String}` | Class names will be camelized, the original class name will be removed from the locals |
1063
- | **`'dashes'`** | `{String}` | Only dashes in class names will be camelized |
1064
- | **`'dashesOnly'`** | `{String}` | Dashes in class names will be camelized, the original class name will be removed from the locals |
1207
+ | Name | Type | Description |
1208
+ | :-------------------: | :------: | :----------------------------------------------------------------------------------------------- |
1209
+ | **`'asIs'`** | `string` | Class names will be exported as is. |
1210
+ | **`'camelCase'`** | `string` | Class names will be camelized, the original class name will not to be removed from the locals |
1211
+ | **`'camelCaseOnly'`** | `string` | Class names will be camelized, the original class name will be removed from the locals |
1212
+ | **`'dashes'`** | `string` | Only dashes in class names will be camelized |
1213
+ | **`'dashesOnly'`** | `string` | Dashes in class names will be camelized, the original class name will be removed from the locals |
1065
1214
 
1066
1215
  **file.css**
1067
1216
 
@@ -1096,7 +1245,7 @@ module.exports = {
1096
1245
  };
1097
1246
  ```
1098
1247
 
1099
- ###### `Function`
1248
+ ###### `function`
1100
1249
 
1101
1250
  **webpack.config.js**
1102
1251
 
@@ -1150,7 +1299,12 @@ module.exports = {
1150
1299
 
1151
1300
  ##### `exportOnlyLocals`
1152
1301
 
1153
- Type: `Boolean`
1302
+ Type:
1303
+
1304
+ ```ts
1305
+ type exportOnlyLocals = boolean;
1306
+ ```
1307
+
1154
1308
  Default: `false`
1155
1309
 
1156
1310
  Export only locals.
@@ -1181,7 +1335,12 @@ module.exports = {
1181
1335
 
1182
1336
  ### `importLoaders`
1183
1337
 
1184
- Type: `Number`
1338
+ Type:
1339
+
1340
+ ```ts
1341
+ type importLoaders = number;
1342
+ ```
1343
+
1185
1344
  Default: `0`
1186
1345
 
1187
1346
  Allows to enables/disables or setups number of loaders applied before CSS loader for `@import` at-rules, CSS modules and ICSS imports, i.e. `@import`/`composes`/`@value value from './values.css'`/etc.
@@ -1220,7 +1379,12 @@ This may change in the future when the module system (i. e. webpack) supports lo
1220
1379
 
1221
1380
  ### `sourceMap`
1222
1381
 
1223
- Type: `Boolean`
1382
+ Type:
1383
+
1384
+ ```ts
1385
+ type sourceMap = boolean;
1386
+ ```
1387
+
1224
1388
  Default: depends on the `compiler.devtool` value
1225
1389
 
1226
1390
  By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option. All values enable source map generation except `eval` and `false` value.
@@ -1245,7 +1409,12 @@ module.exports = {
1245
1409
 
1246
1410
  ### `esModule`
1247
1411
 
1248
- Type: `Boolean`
1412
+ Type:
1413
+
1414
+ ```ts
1415
+ type esModule = boolean;
1416
+ ```
1417
+
1249
1418
  Default: `true`
1250
1419
 
1251
1420
  By default, `css-loader` generates JS modules that use the ES modules syntax.
@@ -1273,7 +1442,12 @@ module.exports = {
1273
1442
 
1274
1443
  ### `exportType`
1275
1444
 
1276
- Type: `'array' | 'string' | 'css-style-sheet'`
1445
+ Type:
1446
+
1447
+ ```ts
1448
+ type exportType = "array" | "string" | "css-style-sheet";
1449
+ ```
1450
+
1277
1451
  Default: `'array'`
1278
1452
 
1279
1453
  Allows exporting styles as array with modules, string or [constructable stylesheet](https://developers.google.com/web/updates/2019/02/constructable-stylesheets) (i.e. [`CSSStyleSheet`](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet)).
package/dist/cjs.js CHANGED
@@ -2,4 +2,5 @@
2
2
 
3
3
  const loader = require("./index");
4
4
 
5
+ module.exports.defaultGetLocalIdent = require("./utils").defaultGetLocalIdent;
5
6
  module.exports = loader.default;
package/dist/utils.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.WEBPACK_IGNORE_COMMENT_REGEXP = void 0;
7
7
  exports.camelCase = camelCase;
8
8
  exports.combineRequests = combineRequests;
9
+ exports.defaultGetLocalIdent = defaultGetLocalIdent;
9
10
  exports.getExportCode = getExportCode;
10
11
  exports.getFilter = getFilter;
11
12
  exports.getImportCode = getImportCode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-loader",
3
- "version": "6.6.0",
3
+ "version": "6.7.0",
4
4
  "description": "css loader module for webpack",
5
5
  "license": "MIT",
6
6
  "repository": "webpack-contrib/css-loader",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "icss-utils": "^5.1.0",
46
- "postcss": "^8.4.5",
46
+ "postcss": "^8.4.7",
47
47
  "postcss-modules-extract-imports": "^3.0.0",
48
48
  "postcss-modules-local-by-default": "^4.0.0",
49
49
  "postcss-modules-scope": "^3.0.0",
@@ -52,41 +52,41 @@
52
52
  "semver": "^7.3.5"
53
53
  },
54
54
  "devDependencies": {
55
- "@babel/cli": "^7.16.8",
56
- "@babel/core": "^7.16.12",
55
+ "@babel/cli": "^7.17.6",
56
+ "@babel/core": "^7.17.5",
57
57
  "@babel/preset-env": "^7.16.11",
58
- "@commitlint/cli": "^16.1.0",
59
- "@commitlint/config-conventional": "^16.0.0",
58
+ "@commitlint/cli": "^16.2.1",
59
+ "@commitlint/config-conventional": "^16.2.1",
60
60
  "@webpack-contrib/eslint-config-webpack": "^3.0.0",
61
- "babel-jest": "^27.4.6",
61
+ "babel-jest": "^27.5.1",
62
62
  "cross-env": "^7.0.3",
63
63
  "del": "^6.0.0",
64
64
  "del-cli": "^4.0.1",
65
- "es-check": "^6.0.0",
66
- "eslint": "^8.7.0",
67
- "eslint-config-prettier": "^8.3.0",
65
+ "es-check": "^6.2.1",
66
+ "eslint": "^8.10.0",
67
+ "eslint-config-prettier": "^8.5.0",
68
68
  "eslint-plugin-import": "^2.25.4",
69
69
  "file-loader": "^6.2.0",
70
70
  "husky": "^7.0.1",
71
- "jest": "^27.4.7",
71
+ "jest": "^27.5.1",
72
72
  "less": "^4.1.1",
73
73
  "less-loader": "^10.0.1",
74
- "lint-staged": "^12.3.2",
74
+ "lint-staged": "^12.3.4",
75
75
  "memfs": "^3.4.1",
76
- "mini-css-extract-plugin": "^2.5.3",
76
+ "mini-css-extract-plugin": "^2.6.0",
77
77
  "npm-run-all": "^4.1.5",
78
78
  "postcss-loader": "^6.2.1",
79
- "postcss-preset-env": "^7.2.3",
79
+ "postcss-preset-env": "^7.4.2",
80
80
  "prettier": "^2.5.1",
81
- "sass": "^1.49.0",
82
- "sass-loader": "^12.4.0",
81
+ "sass": "^1.49.9",
82
+ "sass-loader": "^12.6.0",
83
83
  "standard-version": "^9.3.1",
84
84
  "strip-ansi": "^6.0.0",
85
85
  "style-loader": "^3.1.0",
86
86
  "stylus": "^0.56.0",
87
87
  "stylus-loader": "^6.1.0",
88
88
  "url-loader": "^4.1.1",
89
- "webpack": "^5.67.0"
89
+ "webpack": "^5.70.0"
90
90
  },
91
91
  "keywords": [
92
92
  "webpack",