css-loader 6.5.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 +262 -58
- package/dist/cjs.js +1 -0
- package/dist/options.json +5 -0
- package/dist/utils.js +15 -8
- package/package.json +24 -24
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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:
|
|
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
|
-
#### `
|
|
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
|
-
#### `
|
|
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:
|
|
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
|
-
#### `
|
|
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
|
-
#### `
|
|
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:
|
|
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:
|
|
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
|
-
#### `
|
|
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
|
-
#### `
|
|
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
|
-
#### `
|
|
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:
|
|
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
|
-
###### `
|
|
605
|
+
###### `boolean`
|
|
532
606
|
|
|
533
607
|
Possible values:
|
|
534
608
|
|
|
@@ -579,7 +653,7 @@ module.exports = {
|
|
|
579
653
|
};
|
|
580
654
|
```
|
|
581
655
|
|
|
582
|
-
###### `
|
|
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:
|
|
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
|
-
###### `
|
|
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
|
-
###### `
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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.
|
|
@@ -872,9 +986,44 @@ module.exports = {
|
|
|
872
986
|
};
|
|
873
987
|
```
|
|
874
988
|
|
|
989
|
+
##### `hashStrategy`
|
|
990
|
+
|
|
991
|
+
Type: `'resource-path-and-local-name' | 'minimal-subset'`
|
|
992
|
+
Default: `'resource-path-and-local-name'`
|
|
993
|
+
|
|
994
|
+
Should local name be used when computing the hash.
|
|
995
|
+
|
|
996
|
+
- `'resource-path-and-local-name'` Both resource path and local name are used when hashing. Each identifier in a module gets its own hash digest, always.
|
|
997
|
+
- `'minimal-subset'` Auto detect if identifier names can be omitted from hashing. Use this value to optimize the output for better GZIP or Brotli compression.
|
|
998
|
+
|
|
999
|
+
**webpack.config.js**
|
|
1000
|
+
|
|
1001
|
+
```js
|
|
1002
|
+
module.exports = {
|
|
1003
|
+
module: {
|
|
1004
|
+
rules: [
|
|
1005
|
+
{
|
|
1006
|
+
test: /\.css$/i,
|
|
1007
|
+
loader: "css-loader",
|
|
1008
|
+
options: {
|
|
1009
|
+
modules: {
|
|
1010
|
+
hashStrategy: "minimal-subset",
|
|
1011
|
+
},
|
|
1012
|
+
},
|
|
1013
|
+
},
|
|
1014
|
+
],
|
|
1015
|
+
},
|
|
1016
|
+
};
|
|
1017
|
+
```
|
|
1018
|
+
|
|
875
1019
|
##### `localIdentRegExp`
|
|
876
1020
|
|
|
877
|
-
Type:
|
|
1021
|
+
Type:
|
|
1022
|
+
|
|
1023
|
+
```ts
|
|
1024
|
+
type localIdentRegExp = string | RegExp;
|
|
1025
|
+
```
|
|
1026
|
+
|
|
878
1027
|
Default: `undefined`
|
|
879
1028
|
|
|
880
1029
|
**webpack.config.js**
|
|
@@ -899,7 +1048,16 @@ module.exports = {
|
|
|
899
1048
|
|
|
900
1049
|
##### `getLocalIdent`
|
|
901
1050
|
|
|
902
|
-
Type:
|
|
1051
|
+
Type:
|
|
1052
|
+
|
|
1053
|
+
```ts
|
|
1054
|
+
type getLocalIdent = (
|
|
1055
|
+
context: LoaderContext,
|
|
1056
|
+
localIdentName: string,
|
|
1057
|
+
localName: string
|
|
1058
|
+
) => string;
|
|
1059
|
+
```
|
|
1060
|
+
|
|
903
1061
|
Default: `undefined`
|
|
904
1062
|
|
|
905
1063
|
Allows to specify a function to generate the classname.
|
|
@@ -931,7 +1089,12 @@ module.exports = {
|
|
|
931
1089
|
|
|
932
1090
|
##### `namedExport`
|
|
933
1091
|
|
|
934
|
-
Type:
|
|
1092
|
+
Type:
|
|
1093
|
+
|
|
1094
|
+
```ts
|
|
1095
|
+
type namedExport = boolean;
|
|
1096
|
+
```
|
|
1097
|
+
|
|
935
1098
|
Default: `false`
|
|
936
1099
|
|
|
937
1100
|
Enables/disables ES modules named export for locals.
|
|
@@ -987,7 +1150,12 @@ Example below in the [`examples`](#examples) section.
|
|
|
987
1150
|
|
|
988
1151
|
##### `exportGlobals`
|
|
989
1152
|
|
|
990
|
-
Type:
|
|
1153
|
+
Type:
|
|
1154
|
+
|
|
1155
|
+
```ts
|
|
1156
|
+
type exportsGLobals = boolean;
|
|
1157
|
+
```
|
|
1158
|
+
|
|
991
1159
|
Default: `false`
|
|
992
1160
|
|
|
993
1161
|
Allow `css-loader` to export names from global class or id, so you can use that as local name.
|
|
@@ -1014,24 +1182,35 @@ module.exports = {
|
|
|
1014
1182
|
|
|
1015
1183
|
##### `exportLocalsConvention`
|
|
1016
1184
|
|
|
1017
|
-
Type:
|
|
1185
|
+
Type:
|
|
1186
|
+
|
|
1187
|
+
```ts
|
|
1188
|
+
type exportLocalsConvention =
|
|
1189
|
+
| "asIs"
|
|
1190
|
+
| "camelCase"
|
|
1191
|
+
| "camelCaseOnly"
|
|
1192
|
+
| "dashes"
|
|
1193
|
+
| "dashesOnly"
|
|
1194
|
+
| ((name: string) => string);
|
|
1195
|
+
```
|
|
1196
|
+
|
|
1018
1197
|
Default: based on the `modules.namedExport` option value, if `true` - `camelCaseOnly`, otherwise `asIs`
|
|
1019
1198
|
|
|
1020
1199
|
Style of exported class names.
|
|
1021
1200
|
|
|
1022
|
-
###### `
|
|
1201
|
+
###### `string`
|
|
1023
1202
|
|
|
1024
1203
|
By default, the exported JSON keys mirror the class names (i.e `asIs` value).
|
|
1025
1204
|
|
|
1026
1205
|
> ⚠ Only `camelCaseOnly` value allowed if you set the `namedExport` value to `true`.
|
|
1027
1206
|
|
|
1028
|
-
| Name |
|
|
1029
|
-
| :-------------------: |
|
|
1030
|
-
| **`'asIs'`** | `
|
|
1031
|
-
| **`'camelCase'`** | `
|
|
1032
|
-
| **`'camelCaseOnly'`** | `
|
|
1033
|
-
| **`'dashes'`** | `
|
|
1034
|
-
| **`'dashesOnly'`** | `
|
|
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 |
|
|
1035
1214
|
|
|
1036
1215
|
**file.css**
|
|
1037
1216
|
|
|
@@ -1066,7 +1245,7 @@ module.exports = {
|
|
|
1066
1245
|
};
|
|
1067
1246
|
```
|
|
1068
1247
|
|
|
1069
|
-
###### `
|
|
1248
|
+
###### `function`
|
|
1070
1249
|
|
|
1071
1250
|
**webpack.config.js**
|
|
1072
1251
|
|
|
@@ -1120,7 +1299,12 @@ module.exports = {
|
|
|
1120
1299
|
|
|
1121
1300
|
##### `exportOnlyLocals`
|
|
1122
1301
|
|
|
1123
|
-
Type:
|
|
1302
|
+
Type:
|
|
1303
|
+
|
|
1304
|
+
```ts
|
|
1305
|
+
type exportOnlyLocals = boolean;
|
|
1306
|
+
```
|
|
1307
|
+
|
|
1124
1308
|
Default: `false`
|
|
1125
1309
|
|
|
1126
1310
|
Export only locals.
|
|
@@ -1151,7 +1335,12 @@ module.exports = {
|
|
|
1151
1335
|
|
|
1152
1336
|
### `importLoaders`
|
|
1153
1337
|
|
|
1154
|
-
Type:
|
|
1338
|
+
Type:
|
|
1339
|
+
|
|
1340
|
+
```ts
|
|
1341
|
+
type importLoaders = number;
|
|
1342
|
+
```
|
|
1343
|
+
|
|
1155
1344
|
Default: `0`
|
|
1156
1345
|
|
|
1157
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.
|
|
@@ -1190,7 +1379,12 @@ This may change in the future when the module system (i. e. webpack) supports lo
|
|
|
1190
1379
|
|
|
1191
1380
|
### `sourceMap`
|
|
1192
1381
|
|
|
1193
|
-
Type:
|
|
1382
|
+
Type:
|
|
1383
|
+
|
|
1384
|
+
```ts
|
|
1385
|
+
type sourceMap = boolean;
|
|
1386
|
+
```
|
|
1387
|
+
|
|
1194
1388
|
Default: depends on the `compiler.devtool` value
|
|
1195
1389
|
|
|
1196
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.
|
|
@@ -1215,7 +1409,12 @@ module.exports = {
|
|
|
1215
1409
|
|
|
1216
1410
|
### `esModule`
|
|
1217
1411
|
|
|
1218
|
-
Type:
|
|
1412
|
+
Type:
|
|
1413
|
+
|
|
1414
|
+
```ts
|
|
1415
|
+
type esModule = boolean;
|
|
1416
|
+
```
|
|
1417
|
+
|
|
1219
1418
|
Default: `true`
|
|
1220
1419
|
|
|
1221
1420
|
By default, `css-loader` generates JS modules that use the ES modules syntax.
|
|
@@ -1243,7 +1442,12 @@ module.exports = {
|
|
|
1243
1442
|
|
|
1244
1443
|
### `exportType`
|
|
1245
1444
|
|
|
1246
|
-
Type:
|
|
1445
|
+
Type:
|
|
1446
|
+
|
|
1447
|
+
```ts
|
|
1448
|
+
type exportType = "array" | "string" | "css-style-sheet";
|
|
1449
|
+
```
|
|
1450
|
+
|
|
1247
1451
|
Default: `'array'`
|
|
1248
1452
|
|
|
1249
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)).
|
|
@@ -1446,7 +1650,7 @@ For `production` builds it's recommended to extract the CSS from your bundle bei
|
|
|
1446
1650
|
This can be achieved by using the [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin), because it creates separate css files.
|
|
1447
1651
|
For `development` mode (including `webpack-dev-server`) you can use [style-loader](https://github.com/webpack-contrib/style-loader), because it injects CSS into the DOM using multiple <style></style> and works faster.
|
|
1448
1652
|
|
|
1449
|
-
> i Do not use
|
|
1653
|
+
> i Do not use `style-loader` and `mini-css-extract-plugin` together.
|
|
1450
1654
|
|
|
1451
1655
|
**webpack.config.js**
|
|
1452
1656
|
|
package/dist/cjs.js
CHANGED
package/dist/options.json
CHANGED
|
@@ -114,6 +114,11 @@
|
|
|
114
114
|
"link": "https://github.com/webpack-contrib/css-loader#localidenthashdigestlength",
|
|
115
115
|
"type": "number"
|
|
116
116
|
},
|
|
117
|
+
"hashStrategy": {
|
|
118
|
+
"description": "Allows to specify should localName be used when computing the hash.",
|
|
119
|
+
"link": "https://github.com/webpack-contrib/css-loader#hashstrategy",
|
|
120
|
+
"enum": ["resource-path-and-local-name", "minimal-subset"]
|
|
121
|
+
},
|
|
117
122
|
"localIdentRegExp": {
|
|
118
123
|
"description": "Allows to specify custom RegExp for local ident name.",
|
|
119
124
|
"link": "https://github.com/webpack-contrib/css-loader#localidentregexp",
|
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;
|
|
@@ -60,7 +61,7 @@ function isRelativePath(str) {
|
|
|
60
61
|
|
|
61
62
|
function stringifyRequest(loaderContext, request) {
|
|
62
63
|
if (typeof loaderContext.utils !== "undefined" && typeof loaderContext.utils.contextify === "function") {
|
|
63
|
-
return JSON.stringify(loaderContext.utils.contextify(loaderContext.context, request));
|
|
64
|
+
return JSON.stringify(loaderContext.utils.contextify(loaderContext.context || loaderContext.rootContext, request));
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
const splitted = request.split("!");
|
|
@@ -320,14 +321,15 @@ function escapeLocalIdent(localident) {
|
|
|
320
321
|
function defaultGetLocalIdent(loaderContext, localIdentName, localName, options) {
|
|
321
322
|
const {
|
|
322
323
|
context,
|
|
323
|
-
hashSalt
|
|
324
|
+
hashSalt,
|
|
325
|
+
hashStrategy
|
|
324
326
|
} = options;
|
|
325
327
|
const {
|
|
326
328
|
resourcePath
|
|
327
329
|
} = loaderContext;
|
|
328
330
|
const relativeResourcePath = normalizePath(_path.default.relative(context, resourcePath)); // eslint-disable-next-line no-param-reassign
|
|
329
331
|
|
|
330
|
-
options.content = `${relativeResourcePath}\x00${localName}`;
|
|
332
|
+
options.content = hashStrategy === "minimal-subset" && /\[local\]/.test(localIdentName) ? relativeResourcePath : `${relativeResourcePath}\x00${localName}`;
|
|
331
333
|
let {
|
|
332
334
|
hashFunction,
|
|
333
335
|
hashDigest,
|
|
@@ -349,8 +351,9 @@ function defaultGetLocalIdent(loaderContext, localIdentName, localName, options)
|
|
|
349
351
|
let localIdentHash = "";
|
|
350
352
|
|
|
351
353
|
for (let tier = 0; localIdentHash.length < hashDigestLength; tier++) {
|
|
352
|
-
//
|
|
353
|
-
const hash = loaderContext.
|
|
354
|
+
// TODO remove this in the next major release
|
|
355
|
+
const hash = loaderContext.utils && typeof loaderContext.utils.createHash === "function" ? loaderContext.utils.createHash(hashFunction) : // eslint-disable-next-line no-underscore-dangle
|
|
356
|
+
loaderContext._compiler.webpack.util.createHash(hashFunction);
|
|
354
357
|
|
|
355
358
|
if (hashSalt) {
|
|
356
359
|
hash.update(hashSalt);
|
|
@@ -358,8 +361,9 @@ function defaultGetLocalIdent(loaderContext, localIdentName, localName, options)
|
|
|
358
361
|
|
|
359
362
|
const tierSalt = Buffer.allocUnsafe(4);
|
|
360
363
|
tierSalt.writeUInt32LE(tier);
|
|
361
|
-
hash.update(tierSalt);
|
|
362
|
-
|
|
364
|
+
hash.update(tierSalt); // TODO: bug in webpack with unicode characters with strings
|
|
365
|
+
|
|
366
|
+
hash.update(Buffer.from(options.content, "utf8"));
|
|
363
367
|
localIdentHash = (localIdentHash + hash.digest(hashDigest) // Remove all leading digits
|
|
364
368
|
).replace(/^\d+/, "") // Replace all slashes with underscores (same as in base64url)
|
|
365
369
|
.replace(/\//g, "_") // Remove everything that is not an alphanumeric or underscore
|
|
@@ -695,7 +699,8 @@ function getModulesPlugins(options, loaderContext) {
|
|
|
695
699
|
localIdentHashFunction,
|
|
696
700
|
localIdentHashDigest,
|
|
697
701
|
localIdentHashDigestLength,
|
|
698
|
-
localIdentRegExp
|
|
702
|
+
localIdentRegExp,
|
|
703
|
+
hashStrategy
|
|
699
704
|
} = options.modules;
|
|
700
705
|
let plugins = [];
|
|
701
706
|
|
|
@@ -713,6 +718,7 @@ function getModulesPlugins(options, loaderContext) {
|
|
|
713
718
|
hashFunction: localIdentHashFunction,
|
|
714
719
|
hashDigest: localIdentHashDigest,
|
|
715
720
|
hashDigestLength: localIdentHashDigestLength,
|
|
721
|
+
hashStrategy,
|
|
716
722
|
regExp: localIdentRegExp
|
|
717
723
|
});
|
|
718
724
|
} // A null/undefined value signals that we should invoke the default
|
|
@@ -726,6 +732,7 @@ function getModulesPlugins(options, loaderContext) {
|
|
|
726
732
|
hashFunction: localIdentHashFunction,
|
|
727
733
|
hashDigest: localIdentHashDigest,
|
|
728
734
|
hashDigestLength: localIdentHashDigestLength,
|
|
735
|
+
hashStrategy,
|
|
729
736
|
regExp: localIdentRegExp
|
|
730
737
|
});
|
|
731
738
|
return escapeLocalIdent(localIdent).replace(/\\\[local\\]/gi, exportName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "css-loader",
|
|
3
|
-
"version": "6.
|
|
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,50 +43,50 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"icss-utils": "^5.1.0",
|
|
46
|
-
"postcss": "^8.
|
|
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",
|
|
50
50
|
"postcss-modules-values": "^4.0.0",
|
|
51
|
-
"postcss-value-parser": "^4.
|
|
51
|
+
"postcss-value-parser": "^4.2.0",
|
|
52
52
|
"semver": "^7.3.5"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@babel/cli": "^7.
|
|
56
|
-
"@babel/core": "^7.
|
|
57
|
-
"@babel/preset-env": "^7.
|
|
58
|
-
"@commitlint/cli": "^
|
|
59
|
-
"@commitlint/config-conventional": "^
|
|
55
|
+
"@babel/cli": "^7.17.6",
|
|
56
|
+
"@babel/core": "^7.17.5",
|
|
57
|
+
"@babel/preset-env": "^7.16.11",
|
|
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.
|
|
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.
|
|
66
|
-
"eslint": "^8.
|
|
67
|
-
"eslint-config-prettier": "^8.
|
|
68
|
-
"eslint-plugin-import": "^2.
|
|
65
|
+
"es-check": "^6.2.1",
|
|
66
|
+
"eslint": "^8.10.0",
|
|
67
|
+
"eslint-config-prettier": "^8.5.0",
|
|
68
|
+
"eslint-plugin-import": "^2.25.4",
|
|
69
69
|
"file-loader": "^6.2.0",
|
|
70
70
|
"husky": "^7.0.1",
|
|
71
|
-
"jest": "^27.
|
|
71
|
+
"jest": "^27.5.1",
|
|
72
72
|
"less": "^4.1.1",
|
|
73
73
|
"less-loader": "^10.0.1",
|
|
74
|
-
"lint-staged": "^
|
|
75
|
-
"memfs": "^3.
|
|
76
|
-
"mini-css-extract-plugin": "^2.
|
|
74
|
+
"lint-staged": "^12.3.4",
|
|
75
|
+
"memfs": "^3.4.1",
|
|
76
|
+
"mini-css-extract-plugin": "^2.6.0",
|
|
77
77
|
"npm-run-all": "^4.1.5",
|
|
78
|
-
"postcss-loader": "^6.
|
|
79
|
-
"postcss-preset-env": "^
|
|
80
|
-
"prettier": "^2.
|
|
81
|
-
"sass": "^1.
|
|
82
|
-
"sass-loader": "^12.
|
|
78
|
+
"postcss-loader": "^6.2.1",
|
|
79
|
+
"postcss-preset-env": "^7.4.2",
|
|
80
|
+
"prettier": "^2.5.1",
|
|
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
|
-
"stylus": "^0.
|
|
86
|
+
"stylus": "^0.56.0",
|
|
87
87
|
"stylus-loader": "^6.1.0",
|
|
88
88
|
"url-loader": "^4.1.1",
|
|
89
|
-
"webpack": "^5.
|
|
89
|
+
"webpack": "^5.70.0"
|
|
90
90
|
},
|
|
91
91
|
"keywords": [
|
|
92
92
|
"webpack",
|