css-loader 4.3.0 → 5.1.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/CHANGELOG.md +41 -0
- package/README.md +177 -89
- package/dist/CssSyntaxError.js +5 -3
- package/dist/Warning.js +2 -2
- package/dist/cjs.js +1 -1
- package/dist/index.js +25 -17
- package/dist/options.json +0 -4
- package/dist/plugins/postcss-icss-parser.js +101 -96
- package/dist/plugins/postcss-import-parser.js +201 -176
- package/dist/plugins/postcss-url-parser.js +283 -191
- package/dist/runtime/api.js +6 -34
- package/dist/runtime/cssWithMappingToString.js +32 -0
- package/dist/runtime/getUrl.js +2 -2
- package/dist/utils.js +128 -95
- package/package.json +36 -36
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ Then add the plugin to your `webpack` config. For example:
|
|
|
32
32
|
**file.js**
|
|
33
33
|
|
|
34
34
|
```js
|
|
35
|
-
import css from
|
|
35
|
+
import css from "file.css";
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
**webpack.config.js**
|
|
@@ -43,13 +43,15 @@ module.exports = {
|
|
|
43
43
|
rules: [
|
|
44
44
|
{
|
|
45
45
|
test: /\.css$/i,
|
|
46
|
-
use: [
|
|
46
|
+
use: ["style-loader", "css-loader"],
|
|
47
47
|
},
|
|
48
48
|
],
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
**Only for webpack v4:**
|
|
54
|
+
|
|
53
55
|
Good loaders for requiring your assets are the [file-loader](https://github.com/webpack/file-loader) and the [url-loader](https://github.com/webpack/url-loader) which you should specify in your config (see [below](https://github.com/webpack-contrib/css-loader#assets)).
|
|
54
56
|
|
|
55
57
|
And run `webpack` via your preferred method.
|
|
@@ -66,7 +68,7 @@ module.exports = {
|
|
|
66
68
|
rules: [
|
|
67
69
|
{
|
|
68
70
|
test: /\.css$/i,
|
|
69
|
-
use: [
|
|
71
|
+
use: ["to-string-loader", "css-loader"],
|
|
70
72
|
},
|
|
71
73
|
],
|
|
72
74
|
},
|
|
@@ -76,7 +78,7 @@ module.exports = {
|
|
|
76
78
|
or
|
|
77
79
|
|
|
78
80
|
```js
|
|
79
|
-
const css = require(
|
|
81
|
+
const css = require("./test.css").toString();
|
|
80
82
|
|
|
81
83
|
console.log(css); // {String}
|
|
82
84
|
```
|
|
@@ -97,9 +99,9 @@ module.exports = {
|
|
|
97
99
|
{
|
|
98
100
|
test: /\.css$/i,
|
|
99
101
|
use: [
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
"handlebars-loader", // handlebars loader expects raw resource string
|
|
103
|
+
"extract-loader",
|
|
104
|
+
"css-loader",
|
|
103
105
|
],
|
|
104
106
|
},
|
|
105
107
|
],
|
|
@@ -124,7 +126,7 @@ Type: `Boolean|Function`
|
|
|
124
126
|
Default: `true`
|
|
125
127
|
|
|
126
128
|
Enables/Disables `url`/`image-set` functions handling.
|
|
127
|
-
Control `url()` resolving. Absolute URLs
|
|
129
|
+
Control `url()` resolving. Absolute paths and root-relative URLs now resolving(Version [4.0.0](https://github.com/webpack-contrib/css-loader/blob/master/CHANGELOG.md#400-2020-07-25) and above).
|
|
128
130
|
|
|
129
131
|
Examples resolutions:
|
|
130
132
|
|
|
@@ -157,7 +159,7 @@ module.exports = {
|
|
|
157
159
|
rules: [
|
|
158
160
|
{
|
|
159
161
|
test: /\.css$/i,
|
|
160
|
-
loader:
|
|
162
|
+
loader: "css-loader",
|
|
161
163
|
options: {
|
|
162
164
|
url: true,
|
|
163
165
|
},
|
|
@@ -179,13 +181,13 @@ module.exports = {
|
|
|
179
181
|
rules: [
|
|
180
182
|
{
|
|
181
183
|
test: /\.css$/i,
|
|
182
|
-
loader:
|
|
184
|
+
loader: "css-loader",
|
|
183
185
|
options: {
|
|
184
186
|
url: (url, resourcePath) => {
|
|
185
187
|
// resourcePath - path to css file
|
|
186
188
|
|
|
187
189
|
// Don't handle `img.png` urls
|
|
188
|
-
if (url.includes(
|
|
190
|
+
if (url.includes("img.png")) {
|
|
189
191
|
return false;
|
|
190
192
|
}
|
|
191
193
|
|
|
@@ -238,7 +240,7 @@ module.exports = {
|
|
|
238
240
|
rules: [
|
|
239
241
|
{
|
|
240
242
|
test: /\.css$/i,
|
|
241
|
-
loader:
|
|
243
|
+
loader: "css-loader",
|
|
242
244
|
options: {
|
|
243
245
|
import: true,
|
|
244
246
|
},
|
|
@@ -260,13 +262,13 @@ module.exports = {
|
|
|
260
262
|
rules: [
|
|
261
263
|
{
|
|
262
264
|
test: /\.css$/i,
|
|
263
|
-
loader:
|
|
265
|
+
loader: "css-loader",
|
|
264
266
|
options: {
|
|
265
267
|
import: (url, media, resourcePath) => {
|
|
266
268
|
// resourcePath - path to css file
|
|
267
269
|
|
|
268
270
|
// Don't handle `style.css` import
|
|
269
|
-
if (url.includes(
|
|
271
|
+
if (url.includes("style.css")) {
|
|
270
272
|
return false;
|
|
271
273
|
}
|
|
272
274
|
|
|
@@ -298,7 +300,7 @@ module.exports = {
|
|
|
298
300
|
rules: [
|
|
299
301
|
{
|
|
300
302
|
test: /\.css$/i,
|
|
301
|
-
loader:
|
|
303
|
+
loader: "css-loader",
|
|
302
304
|
options: {
|
|
303
305
|
modules: true,
|
|
304
306
|
},
|
|
@@ -362,8 +364,8 @@ The loader replaces local selectors with unique identifiers. The chosen unique i
|
|
|
362
364
|
|
|
363
365
|
```js
|
|
364
366
|
exports.locals = {
|
|
365
|
-
className:
|
|
366
|
-
subClass:
|
|
367
|
+
className: "_23_aKvs-b8bW2Vg3fwHozO",
|
|
368
|
+
subClass: "_13LGdX8RMStbBE9w-t0gZ1",
|
|
367
369
|
};
|
|
368
370
|
```
|
|
369
371
|
|
|
@@ -391,8 +393,8 @@ This doesn't result in any change to the CSS itself but exports multiple classna
|
|
|
391
393
|
|
|
392
394
|
```js
|
|
393
395
|
exports.locals = {
|
|
394
|
-
className:
|
|
395
|
-
subClass:
|
|
396
|
+
className: "_23_aKvs-b8bW2Vg3fwHozO",
|
|
397
|
+
subClass: "_13LGdX8RMStbBE9w-t0gZ1 _23_aKvs-b8bW2Vg3fwHozO",
|
|
396
398
|
};
|
|
397
399
|
```
|
|
398
400
|
|
|
@@ -415,14 +417,14 @@ To import a local classname from another module.
|
|
|
415
417
|
|
|
416
418
|
```css
|
|
417
419
|
:local(.continueButton) {
|
|
418
|
-
composes: button from
|
|
420
|
+
composes: button from "library/button.css";
|
|
419
421
|
background: red;
|
|
420
422
|
}
|
|
421
423
|
```
|
|
422
424
|
|
|
423
425
|
```css
|
|
424
426
|
:local(.nameEdit) {
|
|
425
|
-
composes: edit highlight from
|
|
427
|
+
composes: edit highlight from "./edit.css";
|
|
426
428
|
background: red;
|
|
427
429
|
}
|
|
428
430
|
```
|
|
@@ -431,8 +433,8 @@ To import from multiple modules use multiple `composes:` rules.
|
|
|
431
433
|
|
|
432
434
|
```css
|
|
433
435
|
:local(.className) {
|
|
434
|
-
composes: edit hightlight from
|
|
435
|
-
composes: button from
|
|
436
|
+
composes: edit hightlight from "./edit.css";
|
|
437
|
+
composes: button from "module/button.css";
|
|
436
438
|
composes: classFromThisModule;
|
|
437
439
|
background: red;
|
|
438
440
|
}
|
|
@@ -477,7 +479,7 @@ module.exports = {
|
|
|
477
479
|
rules: [
|
|
478
480
|
{
|
|
479
481
|
test: /\.css$/i,
|
|
480
|
-
loader:
|
|
482
|
+
loader: "css-loader",
|
|
481
483
|
options: {
|
|
482
484
|
modules: true,
|
|
483
485
|
},
|
|
@@ -499,10 +501,10 @@ module.exports = {
|
|
|
499
501
|
rules: [
|
|
500
502
|
{
|
|
501
503
|
test: /\.css$/i,
|
|
502
|
-
loader:
|
|
504
|
+
loader: "css-loader",
|
|
503
505
|
options: {
|
|
504
506
|
// Using `local` value has same effect like using `modules: true`
|
|
505
|
-
modules:
|
|
507
|
+
modules: "global",
|
|
506
508
|
},
|
|
507
509
|
},
|
|
508
510
|
],
|
|
@@ -522,18 +524,18 @@ module.exports = {
|
|
|
522
524
|
rules: [
|
|
523
525
|
{
|
|
524
526
|
test: /\.css$/i,
|
|
525
|
-
loader:
|
|
527
|
+
loader: "css-loader",
|
|
526
528
|
options: {
|
|
527
529
|
modules: {
|
|
528
|
-
compileType:
|
|
529
|
-
mode:
|
|
530
|
+
compileType: "module",
|
|
531
|
+
mode: "local",
|
|
530
532
|
auto: true,
|
|
531
533
|
exportGlobals: true,
|
|
532
|
-
localIdentName:
|
|
533
|
-
|
|
534
|
-
localIdentHashPrefix:
|
|
534
|
+
localIdentName: "[path][name]__[local]--[hash:base64:5]",
|
|
535
|
+
localIdentContext: path.resolve(__dirname, "src"),
|
|
536
|
+
localIdentHashPrefix: "my-custom-hash",
|
|
535
537
|
namedExport: true,
|
|
536
|
-
exportLocalsConvention:
|
|
538
|
+
exportLocalsConvention: "camelCase",
|
|
537
539
|
exportOnlyLocals: false,
|
|
538
540
|
},
|
|
539
541
|
},
|
|
@@ -563,10 +565,10 @@ module.exports = {
|
|
|
563
565
|
rules: [
|
|
564
566
|
{
|
|
565
567
|
test: /\.css$/i,
|
|
566
|
-
loader:
|
|
568
|
+
loader: "css-loader",
|
|
567
569
|
options: {
|
|
568
570
|
modules: {
|
|
569
|
-
compileType:
|
|
571
|
+
compileType: "icss",
|
|
570
572
|
},
|
|
571
573
|
},
|
|
572
574
|
},
|
|
@@ -586,8 +588,8 @@ Allows auto enable CSS modules based on filename.
|
|
|
586
588
|
|
|
587
589
|
Possible values:
|
|
588
590
|
|
|
589
|
-
- `true` -
|
|
590
|
-
- `false` -
|
|
591
|
+
- `true` - enables CSS modules or interoperable CSS format, sets the [`modules.compileType`](#compiletype) option to `module` value for all files which satisfy `/\.module(s)?\.\w+$/i.test(filename)` condition or sets the [`modules.compileType`](#compiletype) option to `icss` value for all files which satisfy `/\.icss\.\w+$/i.test(filename)` condition
|
|
592
|
+
- `false` - disables CSS modules or interoperable CSS format based on filename
|
|
591
593
|
|
|
592
594
|
**webpack.config.js**
|
|
593
595
|
|
|
@@ -597,7 +599,7 @@ module.exports = {
|
|
|
597
599
|
rules: [
|
|
598
600
|
{
|
|
599
601
|
test: /\.css$/i,
|
|
600
|
-
loader:
|
|
602
|
+
loader: "css-loader",
|
|
601
603
|
options: {
|
|
602
604
|
modules: {
|
|
603
605
|
auto: true,
|
|
@@ -621,7 +623,7 @@ module.exports = {
|
|
|
621
623
|
rules: [
|
|
622
624
|
{
|
|
623
625
|
test: /\.css$/i,
|
|
624
|
-
loader:
|
|
626
|
+
loader: "css-loader",
|
|
625
627
|
options: {
|
|
626
628
|
modules: {
|
|
627
629
|
auto: /\.custom-module\.\w+$/i,
|
|
@@ -645,10 +647,10 @@ module.exports = {
|
|
|
645
647
|
rules: [
|
|
646
648
|
{
|
|
647
649
|
test: /\.css$/i,
|
|
648
|
-
loader:
|
|
650
|
+
loader: "css-loader",
|
|
649
651
|
options: {
|
|
650
652
|
modules: {
|
|
651
|
-
auto: (resourcePath) => resourcePath.endsWith(
|
|
653
|
+
auto: (resourcePath) => resourcePath.endsWith(".custom-module.css"),
|
|
652
654
|
},
|
|
653
655
|
},
|
|
654
656
|
},
|
|
@@ -676,10 +678,10 @@ module.exports = {
|
|
|
676
678
|
rules: [
|
|
677
679
|
{
|
|
678
680
|
test: /\.css$/i,
|
|
679
|
-
loader:
|
|
681
|
+
loader: "css-loader",
|
|
680
682
|
options: {
|
|
681
683
|
modules: {
|
|
682
|
-
mode:
|
|
684
|
+
mode: "global",
|
|
683
685
|
},
|
|
684
686
|
},
|
|
685
687
|
},
|
|
@@ -702,20 +704,20 @@ module.exports = {
|
|
|
702
704
|
rules: [
|
|
703
705
|
{
|
|
704
706
|
test: /\.css$/i,
|
|
705
|
-
loader:
|
|
707
|
+
loader: "css-loader",
|
|
706
708
|
options: {
|
|
707
709
|
modules: {
|
|
708
710
|
// Callback must return "local", "global", or "pure" values
|
|
709
711
|
mode: (resourcePath) => {
|
|
710
712
|
if (/pure.css$/i.test(resourcePath)) {
|
|
711
|
-
return
|
|
713
|
+
return "pure";
|
|
712
714
|
}
|
|
713
715
|
|
|
714
716
|
if (/global.css$/i.test(resourcePath)) {
|
|
715
|
-
return
|
|
717
|
+
return "global";
|
|
716
718
|
}
|
|
717
719
|
|
|
718
|
-
return
|
|
720
|
+
return "local";
|
|
719
721
|
},
|
|
720
722
|
},
|
|
721
723
|
},
|
|
@@ -750,10 +752,10 @@ module.exports = {
|
|
|
750
752
|
rules: [
|
|
751
753
|
{
|
|
752
754
|
test: /\.css$/i,
|
|
753
|
-
loader:
|
|
755
|
+
loader: "css-loader",
|
|
754
756
|
options: {
|
|
755
757
|
modules: {
|
|
756
|
-
localIdentName:
|
|
758
|
+
localIdentName: "[path][name]__[local]--[hash:base64:5]",
|
|
757
759
|
},
|
|
758
760
|
},
|
|
759
761
|
},
|
|
@@ -777,10 +779,10 @@ module.exports = {
|
|
|
777
779
|
rules: [
|
|
778
780
|
{
|
|
779
781
|
test: /\.css$/i,
|
|
780
|
-
loader:
|
|
782
|
+
loader: "css-loader",
|
|
781
783
|
options: {
|
|
782
784
|
modules: {
|
|
783
|
-
|
|
785
|
+
localIdentContext: path.resolve(__dirname, "src"),
|
|
784
786
|
},
|
|
785
787
|
},
|
|
786
788
|
},
|
|
@@ -804,10 +806,10 @@ module.exports = {
|
|
|
804
806
|
rules: [
|
|
805
807
|
{
|
|
806
808
|
test: /\.css$/i,
|
|
807
|
-
loader:
|
|
809
|
+
loader: "css-loader",
|
|
808
810
|
options: {
|
|
809
811
|
modules: {
|
|
810
|
-
localIdentHashPrefix:
|
|
812
|
+
localIdentHashPrefix: "hash",
|
|
811
813
|
},
|
|
812
814
|
},
|
|
813
815
|
},
|
|
@@ -829,7 +831,7 @@ module.exports = {
|
|
|
829
831
|
rules: [
|
|
830
832
|
{
|
|
831
833
|
test: /\.css$/i,
|
|
832
|
-
loader:
|
|
834
|
+
loader: "css-loader",
|
|
833
835
|
options: {
|
|
834
836
|
modules: {
|
|
835
837
|
localIdentRegExp: /page-(.*)\.css/i,
|
|
@@ -848,6 +850,8 @@ Default: `undefined`
|
|
|
848
850
|
|
|
849
851
|
Allows to specify a function to generate the classname.
|
|
850
852
|
By default we use built-in function to generate a classname.
|
|
853
|
+
If the custom function returns `null` or `undefined`, we fallback to the
|
|
854
|
+
built-in function to generate the classname.
|
|
851
855
|
|
|
852
856
|
**webpack.config.js**
|
|
853
857
|
|
|
@@ -857,11 +861,11 @@ module.exports = {
|
|
|
857
861
|
rules: [
|
|
858
862
|
{
|
|
859
863
|
test: /\.css$/i,
|
|
860
|
-
loader:
|
|
864
|
+
loader: "css-loader",
|
|
861
865
|
options: {
|
|
862
866
|
modules: {
|
|
863
867
|
getLocalIdent: (context, localIdentName, localName, options) => {
|
|
864
|
-
return
|
|
868
|
+
return "whatever_random_class_name";
|
|
865
869
|
},
|
|
866
870
|
},
|
|
867
871
|
},
|
|
@@ -896,7 +900,7 @@ Enables/disables ES modules named export for locals.
|
|
|
896
900
|
**index.js**
|
|
897
901
|
|
|
898
902
|
```js
|
|
899
|
-
import { fooBaz, bar } from
|
|
903
|
+
import { fooBaz, bar } from "./styles.css";
|
|
900
904
|
|
|
901
905
|
console.log(fooBaz, bar);
|
|
902
906
|
```
|
|
@@ -911,7 +915,7 @@ module.exports = {
|
|
|
911
915
|
rules: [
|
|
912
916
|
{
|
|
913
917
|
test: /\.css$/i,
|
|
914
|
-
loader:
|
|
918
|
+
loader: "css-loader",
|
|
915
919
|
options: {
|
|
916
920
|
esModule: true,
|
|
917
921
|
modules: {
|
|
@@ -939,7 +943,7 @@ module.exports = {
|
|
|
939
943
|
rules: [
|
|
940
944
|
{
|
|
941
945
|
test: /\.css$/i,
|
|
942
|
-
loader:
|
|
946
|
+
loader: "css-loader",
|
|
943
947
|
options: {
|
|
944
948
|
modules: {
|
|
945
949
|
exportGlobals: true,
|
|
@@ -980,7 +984,7 @@ By default, the exported JSON keys mirror the class names (i.e `asIs` value).
|
|
|
980
984
|
**file.js**
|
|
981
985
|
|
|
982
986
|
```js
|
|
983
|
-
import { className } from
|
|
987
|
+
import { className } from "file.css";
|
|
984
988
|
```
|
|
985
989
|
|
|
986
990
|
**webpack.config.js**
|
|
@@ -991,10 +995,11 @@ module.exports = {
|
|
|
991
995
|
rules: [
|
|
992
996
|
{
|
|
993
997
|
test: /\.css$/i,
|
|
994
|
-
loader:
|
|
998
|
+
loader: "css-loader",
|
|
995
999
|
options: {
|
|
996
|
-
|
|
997
|
-
|
|
1000
|
+
modules: {
|
|
1001
|
+
exportLocalsConvention: "camelCase",
|
|
1002
|
+
},
|
|
998
1003
|
},
|
|
999
1004
|
},
|
|
1000
1005
|
],
|
|
@@ -1021,7 +1026,7 @@ module.exports = {
|
|
|
1021
1026
|
rules: [
|
|
1022
1027
|
{
|
|
1023
1028
|
test: /\.css$/i,
|
|
1024
|
-
loader:
|
|
1029
|
+
loader: "css-loader",
|
|
1025
1030
|
options: {
|
|
1026
1031
|
modules: {
|
|
1027
1032
|
exportOnlyLocals: true,
|
|
@@ -1048,7 +1053,7 @@ module.exports = {
|
|
|
1048
1053
|
rules: [
|
|
1049
1054
|
{
|
|
1050
1055
|
test: /\.css$/i,
|
|
1051
|
-
loader:
|
|
1056
|
+
loader: "css-loader",
|
|
1052
1057
|
options: {
|
|
1053
1058
|
sourceMap: true,
|
|
1054
1059
|
},
|
|
@@ -1076,9 +1081,9 @@ module.exports = {
|
|
|
1076
1081
|
{
|
|
1077
1082
|
test: /\.css$/i,
|
|
1078
1083
|
use: [
|
|
1079
|
-
|
|
1084
|
+
"style-loader",
|
|
1080
1085
|
{
|
|
1081
|
-
loader:
|
|
1086
|
+
loader: "css-loader",
|
|
1082
1087
|
options: {
|
|
1083
1088
|
importLoaders: 2,
|
|
1084
1089
|
// 0 => no loaders (default);
|
|
@@ -1086,8 +1091,8 @@ module.exports = {
|
|
|
1086
1091
|
// 2 => postcss-loader, sass-loader
|
|
1087
1092
|
},
|
|
1088
1093
|
},
|
|
1089
|
-
|
|
1090
|
-
|
|
1094
|
+
"postcss-loader",
|
|
1095
|
+
"sass-loader",
|
|
1091
1096
|
],
|
|
1092
1097
|
},
|
|
1093
1098
|
],
|
|
@@ -1115,7 +1120,7 @@ module.exports = {
|
|
|
1115
1120
|
rules: [
|
|
1116
1121
|
{
|
|
1117
1122
|
test: /\.css$/i,
|
|
1118
|
-
loader:
|
|
1123
|
+
loader: "css-loader",
|
|
1119
1124
|
options: {
|
|
1120
1125
|
esModule: false,
|
|
1121
1126
|
},
|
|
@@ -1127,10 +1132,66 @@ module.exports = {
|
|
|
1127
1132
|
|
|
1128
1133
|
## Examples
|
|
1129
1134
|
|
|
1135
|
+
### Disable url resolving using the `/* webpackIgnore: true */` comment
|
|
1136
|
+
|
|
1137
|
+
With the help of the `/* webpackIgnore: true */`comment, it is possible to disable sources handling for rules and for individual declarations.
|
|
1138
|
+
|
|
1139
|
+
```css
|
|
1140
|
+
/* webpackIgnore: true */
|
|
1141
|
+
@import url(./basic.css);
|
|
1142
|
+
@import /* webpackIgnore: true */ url(./imported.css);
|
|
1143
|
+
|
|
1144
|
+
.class {
|
|
1145
|
+
/* Disabled url handling for the all urls in the 'background' declaration */
|
|
1146
|
+
color: red;
|
|
1147
|
+
/* webpackIgnore: true */
|
|
1148
|
+
background: url("./url/img.png"), url("./url/img.png");
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
.class {
|
|
1152
|
+
/* Disabled url handling for the first url in the 'background' declaration */
|
|
1153
|
+
color: red;
|
|
1154
|
+
background:
|
|
1155
|
+
/* webpackIgnore: true */ url("./url/img.png"), url("./url/img.png");
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
.class {
|
|
1159
|
+
/* Disabled url handling for the second url in the 'background' declaration */
|
|
1160
|
+
color: red;
|
|
1161
|
+
background: url("./url/img.png"),
|
|
1162
|
+
/* webpackIgnore: true */ url("./url/img.png");
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
/* prettier-ignore */
|
|
1166
|
+
.class {
|
|
1167
|
+
/* Disabled url handling for the second url in the 'background' declaration */
|
|
1168
|
+
color: red;
|
|
1169
|
+
background: url("./url/img.png"),
|
|
1170
|
+
/* webpackIgnore: true */
|
|
1171
|
+
url("./url/img.png");
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
/* prettier-ignore */
|
|
1175
|
+
.class {
|
|
1176
|
+
/* Disabled url handling for third and sixth urls in the 'background-image' declaration */
|
|
1177
|
+
background-image: image-set(
|
|
1178
|
+
url(./url/img.png) 2x,
|
|
1179
|
+
url(./url/img.png) 3x,
|
|
1180
|
+
/* webpackIgnore: true */ url(./url/img.png) 4x,
|
|
1181
|
+
url(./url/img.png) 5x,
|
|
1182
|
+
url(./url/img.png) 6x,
|
|
1183
|
+
/* webpackIgnore: true */
|
|
1184
|
+
url(./url/img.png) 7x
|
|
1185
|
+
);
|
|
1186
|
+
}
|
|
1187
|
+
```
|
|
1188
|
+
|
|
1130
1189
|
### Assets
|
|
1131
1190
|
|
|
1132
1191
|
The following `webpack.config.js` can load CSS files, embed small PNG/JPG/GIF/SVG images as well as fonts as [Data URLs](https://tools.ietf.org/html/rfc2397) and copy larger files to the output directory.
|
|
1133
1192
|
|
|
1193
|
+
**For webpack v5:**
|
|
1194
|
+
|
|
1134
1195
|
**webpack.config.js**
|
|
1135
1196
|
|
|
1136
1197
|
```js
|
|
@@ -1139,11 +1200,33 @@ module.exports = {
|
|
|
1139
1200
|
rules: [
|
|
1140
1201
|
{
|
|
1141
1202
|
test: /\.css$/i,
|
|
1142
|
-
use: [
|
|
1203
|
+
use: ["style-loader", "css-loader"],
|
|
1143
1204
|
},
|
|
1144
1205
|
{
|
|
1145
1206
|
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
|
|
1146
|
-
|
|
1207
|
+
// More information here https://webpack.js.org/guides/asset-modules/
|
|
1208
|
+
type: "asset",
|
|
1209
|
+
},
|
|
1210
|
+
],
|
|
1211
|
+
},
|
|
1212
|
+
};
|
|
1213
|
+
```
|
|
1214
|
+
|
|
1215
|
+
**For webpack v4:**
|
|
1216
|
+
|
|
1217
|
+
**webpack.config.js**
|
|
1218
|
+
|
|
1219
|
+
```js
|
|
1220
|
+
module.exports = {
|
|
1221
|
+
module: {
|
|
1222
|
+
rules: [
|
|
1223
|
+
{
|
|
1224
|
+
test: /\.css$/i,
|
|
1225
|
+
use: ["style-loader", "css-loader"],
|
|
1226
|
+
},
|
|
1227
|
+
{
|
|
1228
|
+
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
|
|
1229
|
+
loader: "url-loader",
|
|
1147
1230
|
options: {
|
|
1148
1231
|
limit: 8192,
|
|
1149
1232
|
},
|
|
@@ -1177,34 +1260,39 @@ module.exports = {
|
|
|
1177
1260
|
// For Less - /\.((c|le)ss)$/i,
|
|
1178
1261
|
test: /\.((c|sa|sc)ss)$/i,
|
|
1179
1262
|
use: [
|
|
1180
|
-
|
|
1263
|
+
"style-loader",
|
|
1181
1264
|
{
|
|
1182
|
-
loader:
|
|
1265
|
+
loader: "css-loader",
|
|
1183
1266
|
options: {
|
|
1184
1267
|
// Run `postcss-loader` on each CSS `@import`, do not forget that `sass-loader` compile non CSS `@import`'s into a single file
|
|
1185
1268
|
// If you need run `sass-loader` and `postcss-loader` on each CSS `@import` please set it to `2`
|
|
1186
1269
|
importLoaders: 1,
|
|
1187
|
-
// Automatically enable css modules for files satisfying `/\.module\.\w+$/i` RegExp.
|
|
1188
|
-
modules: { auto: true },
|
|
1189
1270
|
},
|
|
1190
1271
|
},
|
|
1191
1272
|
{
|
|
1192
|
-
loader:
|
|
1273
|
+
loader: "postcss-loader",
|
|
1193
1274
|
options: { plugins: () => [postcssPresetEnv({ stage: 0 })] },
|
|
1194
1275
|
},
|
|
1195
1276
|
// Can be `less-loader`
|
|
1196
1277
|
{
|
|
1197
|
-
loader:
|
|
1278
|
+
loader: "sass-loader",
|
|
1198
1279
|
},
|
|
1199
1280
|
],
|
|
1200
1281
|
},
|
|
1282
|
+
// For webpack v5
|
|
1201
1283
|
{
|
|
1202
1284
|
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
limit: 8192,
|
|
1206
|
-
},
|
|
1285
|
+
// More information here https://webpack.js.org/guides/asset-modules/
|
|
1286
|
+
type: "asset",
|
|
1207
1287
|
},
|
|
1288
|
+
// For webpack v4
|
|
1289
|
+
// {
|
|
1290
|
+
// test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
|
|
1291
|
+
// loader: "url-loader",
|
|
1292
|
+
// options: {
|
|
1293
|
+
// limit: 8192,
|
|
1294
|
+
// },
|
|
1295
|
+
// },
|
|
1208
1296
|
],
|
|
1209
1297
|
},
|
|
1210
1298
|
};
|
|
@@ -1228,15 +1316,15 @@ module.exports = {
|
|
|
1228
1316
|
rules: [
|
|
1229
1317
|
{
|
|
1230
1318
|
test: /\.css$/i,
|
|
1231
|
-
use: [
|
|
1319
|
+
use: ["style-loader", "css-loader"],
|
|
1232
1320
|
},
|
|
1233
1321
|
],
|
|
1234
1322
|
},
|
|
1235
1323
|
resolve: {
|
|
1236
1324
|
alias: {
|
|
1237
|
-
|
|
1325
|
+
"/assets/unresolved/img.png": path.resolve(
|
|
1238
1326
|
__dirname,
|
|
1239
|
-
|
|
1327
|
+
"assets/real-path-to-img/img.png"
|
|
1240
1328
|
),
|
|
1241
1329
|
},
|
|
1242
1330
|
},
|
|
@@ -1245,7 +1333,7 @@ module.exports = {
|
|
|
1245
1333
|
|
|
1246
1334
|
### Separating `Interoperable CSS`-only and `CSS Module` features
|
|
1247
1335
|
|
|
1248
|
-
The following setup is an example of allowing `Interoperable CSS` features only (such as `:import` and `:export`) without using further `CSS Module` functionality by setting `compileType` option for all files that do not match `*.module.scss` naming convention. This is for reference as having `ICSS` features applied to all files was default `css-loader` behavior before v4.
|
|
1336
|
+
The following setup is an example of allowing `Interoperable CSS` features only (such as `:import` and `:export`) without using further `CSS Module` functionality by setting `compileType` option for all files that do not match `*.module.scss` naming convention. This is for reference as having `ICSS` features applied to all files was default `css-loader` behavior before v4.
|
|
1249
1337
|
Meanwhile all files matching `*.module.scss` are treated as `CSS Modules` in this example.
|
|
1250
1338
|
|
|
1251
1339
|
An example case is assumed where a project requires canvas drawing variables to be synchronized with CSS - canvas drawing uses the same color (set by color name in JavaScript) as HTML background (set by class name in CSS).
|
|
@@ -1324,7 +1412,7 @@ $colorBackground: red;
|
|
|
1324
1412
|
File treated as `CSS Module`.
|
|
1325
1413
|
|
|
1326
1414
|
```scss
|
|
1327
|
-
@import
|
|
1415
|
+
@import "variables.scss";
|
|
1328
1416
|
.componentClass {
|
|
1329
1417
|
background-color: $colorBackground;
|
|
1330
1418
|
}
|
|
@@ -1335,8 +1423,8 @@ File treated as `CSS Module`.
|
|
|
1335
1423
|
Using both `CSS Module` functionality as well as SCSS variables directly in JavaScript.
|
|
1336
1424
|
|
|
1337
1425
|
```jsx
|
|
1338
|
-
import svars from
|
|
1339
|
-
import styles from
|
|
1426
|
+
import svars from "variables.scss";
|
|
1427
|
+
import styles from "Component.module.scss";
|
|
1340
1428
|
|
|
1341
1429
|
// Render DOM with CSS modules class name
|
|
1342
1430
|
// <div className={styles.componentClass}>
|
package/dist/CssSyntaxError.js
CHANGED
|
@@ -11,17 +11,19 @@ class CssSyntaxError extends Error {
|
|
|
11
11
|
const {
|
|
12
12
|
reason,
|
|
13
13
|
line,
|
|
14
|
-
column
|
|
14
|
+
column,
|
|
15
|
+
file
|
|
15
16
|
} = error;
|
|
16
|
-
this.name =
|
|
17
|
+
this.name = "CssSyntaxError"; // Based on https://github.com/postcss/postcss/blob/master/lib/css-syntax-error.es6#L132
|
|
17
18
|
// We don't need `plugin` and `file` properties.
|
|
18
19
|
|
|
19
20
|
this.message = `${this.name}\n\n`;
|
|
20
21
|
|
|
21
|
-
if (typeof line !==
|
|
22
|
+
if (typeof line !== "undefined") {
|
|
22
23
|
this.message += `(${line}:${column}) `;
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
this.message += file ? `${file} ` : "<css input> ";
|
|
25
27
|
this.message += `${reason}`;
|
|
26
28
|
const code = error.showSourceCode();
|
|
27
29
|
|