css-loader 5.0.0 → 5.1.1
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 +28 -0
- package/README.md +174 -88
- package/dist/CssSyntaxError.js +3 -3
- package/dist/Warning.js +2 -2
- package/dist/cjs.js +1 -1
- package/dist/index.js +17 -17
- package/dist/plugins/postcss-icss-parser.js +4 -4
- package/dist/plugins/postcss-import-parser.js +29 -10
- package/dist/plugins/postcss-url-parser.js +107 -19
- package/dist/runtime/api.js +3 -3
- package/dist/runtime/cssWithMappingToString.js +4 -4
- package/dist/runtime/getUrl.js +2 -2
- package/dist/utils.js +81 -80
- package/package.json +25 -25
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [5.1.1](https://github.com/webpack-contrib/css-loader/compare/v5.1.0...v5.1.1) (2021-03-01)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* crash on modified AST from `postcss-loader` ([#1268](https://github.com/webpack-contrib/css-loader/issues/1268)) ([d2a1a84](https://github.com/webpack-contrib/css-loader/commit/d2a1a84afc63fdfb2a4ce6668ed9f2d7f1ba56ca))
|
|
11
|
+
|
|
12
|
+
## [5.1.0](https://github.com/webpack-contrib/css-loader/compare/v5.0.2...v5.1.0) (2021-02-25)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* added support webpackIgnore comment ([#1264](https://github.com/webpack-contrib/css-loader/issues/1264)) ([53d40a9](https://github.com/webpack-contrib/css-loader/commit/53d40a9bb35a79e6a15308bbb7a01358f39816df))
|
|
18
|
+
|
|
19
|
+
### [5.0.2](https://github.com/webpack-contrib/css-loader/compare/v5.0.1...v5.0.2) (2021-02-08)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* pass query with hash to other loaders ([#1261](https://github.com/webpack-contrib/css-loader/issues/1261)) ([729a314](https://github.com/webpack-contrib/css-loader/commit/729a314529cd0607c374b07bdf425337f9a778d4))
|
|
25
|
+
|
|
26
|
+
### [5.0.1](https://github.com/webpack-contrib/css-loader/compare/v5.0.0...v5.0.1) (2020-11-04)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
* sources in source maps have relative paths ([#1219](https://github.com/webpack-contrib/css-loader/issues/1219)) ([3229b3c](https://github.com/webpack-contrib/css-loader/commit/3229b3cca3cb5d762daeff57239a965b06fd7593))
|
|
32
|
+
|
|
5
33
|
## [5.0.0](https://github.com/webpack-contrib/css-loader/compare/v4.3.0...v5.0.0) (2020-10-13)
|
|
6
34
|
|
|
7
35
|
|
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
|
-
localIdentContext: path.resolve(__dirname,
|
|
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
|
-
localIdentContext: path.resolve(__dirname,
|
|
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,
|
|
@@ -859,11 +861,11 @@ module.exports = {
|
|
|
859
861
|
rules: [
|
|
860
862
|
{
|
|
861
863
|
test: /\.css$/i,
|
|
862
|
-
loader:
|
|
864
|
+
loader: "css-loader",
|
|
863
865
|
options: {
|
|
864
866
|
modules: {
|
|
865
867
|
getLocalIdent: (context, localIdentName, localName, options) => {
|
|
866
|
-
return
|
|
868
|
+
return "whatever_random_class_name";
|
|
867
869
|
},
|
|
868
870
|
},
|
|
869
871
|
},
|
|
@@ -898,7 +900,7 @@ Enables/disables ES modules named export for locals.
|
|
|
898
900
|
**index.js**
|
|
899
901
|
|
|
900
902
|
```js
|
|
901
|
-
import { fooBaz, bar } from
|
|
903
|
+
import { fooBaz, bar } from "./styles.css";
|
|
902
904
|
|
|
903
905
|
console.log(fooBaz, bar);
|
|
904
906
|
```
|
|
@@ -913,7 +915,7 @@ module.exports = {
|
|
|
913
915
|
rules: [
|
|
914
916
|
{
|
|
915
917
|
test: /\.css$/i,
|
|
916
|
-
loader:
|
|
918
|
+
loader: "css-loader",
|
|
917
919
|
options: {
|
|
918
920
|
esModule: true,
|
|
919
921
|
modules: {
|
|
@@ -941,7 +943,7 @@ module.exports = {
|
|
|
941
943
|
rules: [
|
|
942
944
|
{
|
|
943
945
|
test: /\.css$/i,
|
|
944
|
-
loader:
|
|
946
|
+
loader: "css-loader",
|
|
945
947
|
options: {
|
|
946
948
|
modules: {
|
|
947
949
|
exportGlobals: true,
|
|
@@ -982,7 +984,7 @@ By default, the exported JSON keys mirror the class names (i.e `asIs` value).
|
|
|
982
984
|
**file.js**
|
|
983
985
|
|
|
984
986
|
```js
|
|
985
|
-
import { className } from
|
|
987
|
+
import { className } from "file.css";
|
|
986
988
|
```
|
|
987
989
|
|
|
988
990
|
**webpack.config.js**
|
|
@@ -993,10 +995,11 @@ module.exports = {
|
|
|
993
995
|
rules: [
|
|
994
996
|
{
|
|
995
997
|
test: /\.css$/i,
|
|
996
|
-
loader:
|
|
998
|
+
loader: "css-loader",
|
|
997
999
|
options: {
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
+
modules: {
|
|
1001
|
+
exportLocalsConvention: "camelCase",
|
|
1002
|
+
},
|
|
1000
1003
|
},
|
|
1001
1004
|
},
|
|
1002
1005
|
],
|
|
@@ -1023,7 +1026,7 @@ module.exports = {
|
|
|
1023
1026
|
rules: [
|
|
1024
1027
|
{
|
|
1025
1028
|
test: /\.css$/i,
|
|
1026
|
-
loader:
|
|
1029
|
+
loader: "css-loader",
|
|
1027
1030
|
options: {
|
|
1028
1031
|
modules: {
|
|
1029
1032
|
exportOnlyLocals: true,
|
|
@@ -1050,7 +1053,7 @@ module.exports = {
|
|
|
1050
1053
|
rules: [
|
|
1051
1054
|
{
|
|
1052
1055
|
test: /\.css$/i,
|
|
1053
|
-
loader:
|
|
1056
|
+
loader: "css-loader",
|
|
1054
1057
|
options: {
|
|
1055
1058
|
sourceMap: true,
|
|
1056
1059
|
},
|
|
@@ -1078,9 +1081,9 @@ module.exports = {
|
|
|
1078
1081
|
{
|
|
1079
1082
|
test: /\.css$/i,
|
|
1080
1083
|
use: [
|
|
1081
|
-
|
|
1084
|
+
"style-loader",
|
|
1082
1085
|
{
|
|
1083
|
-
loader:
|
|
1086
|
+
loader: "css-loader",
|
|
1084
1087
|
options: {
|
|
1085
1088
|
importLoaders: 2,
|
|
1086
1089
|
// 0 => no loaders (default);
|
|
@@ -1088,8 +1091,8 @@ module.exports = {
|
|
|
1088
1091
|
// 2 => postcss-loader, sass-loader
|
|
1089
1092
|
},
|
|
1090
1093
|
},
|
|
1091
|
-
|
|
1092
|
-
|
|
1094
|
+
"postcss-loader",
|
|
1095
|
+
"sass-loader",
|
|
1093
1096
|
],
|
|
1094
1097
|
},
|
|
1095
1098
|
],
|
|
@@ -1117,7 +1120,7 @@ module.exports = {
|
|
|
1117
1120
|
rules: [
|
|
1118
1121
|
{
|
|
1119
1122
|
test: /\.css$/i,
|
|
1120
|
-
loader:
|
|
1123
|
+
loader: "css-loader",
|
|
1121
1124
|
options: {
|
|
1122
1125
|
esModule: false,
|
|
1123
1126
|
},
|
|
@@ -1129,10 +1132,66 @@ module.exports = {
|
|
|
1129
1132
|
|
|
1130
1133
|
## Examples
|
|
1131
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
|
+
|
|
1132
1189
|
### Assets
|
|
1133
1190
|
|
|
1134
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.
|
|
1135
1192
|
|
|
1193
|
+
**For webpack v5:**
|
|
1194
|
+
|
|
1136
1195
|
**webpack.config.js**
|
|
1137
1196
|
|
|
1138
1197
|
```js
|
|
@@ -1141,11 +1200,33 @@ module.exports = {
|
|
|
1141
1200
|
rules: [
|
|
1142
1201
|
{
|
|
1143
1202
|
test: /\.css$/i,
|
|
1144
|
-
use: [
|
|
1203
|
+
use: ["style-loader", "css-loader"],
|
|
1145
1204
|
},
|
|
1146
1205
|
{
|
|
1147
1206
|
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
|
|
1148
|
-
|
|
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",
|
|
1149
1230
|
options: {
|
|
1150
1231
|
limit: 8192,
|
|
1151
1232
|
},
|
|
@@ -1179,34 +1260,39 @@ module.exports = {
|
|
|
1179
1260
|
// For Less - /\.((c|le)ss)$/i,
|
|
1180
1261
|
test: /\.((c|sa|sc)ss)$/i,
|
|
1181
1262
|
use: [
|
|
1182
|
-
|
|
1263
|
+
"style-loader",
|
|
1183
1264
|
{
|
|
1184
|
-
loader:
|
|
1265
|
+
loader: "css-loader",
|
|
1185
1266
|
options: {
|
|
1186
1267
|
// Run `postcss-loader` on each CSS `@import`, do not forget that `sass-loader` compile non CSS `@import`'s into a single file
|
|
1187
1268
|
// If you need run `sass-loader` and `postcss-loader` on each CSS `@import` please set it to `2`
|
|
1188
1269
|
importLoaders: 1,
|
|
1189
|
-
// Automatically enable css modules for files satisfying `/\.module\.\w+$/i` RegExp.
|
|
1190
|
-
modules: { auto: true },
|
|
1191
1270
|
},
|
|
1192
1271
|
},
|
|
1193
1272
|
{
|
|
1194
|
-
loader:
|
|
1273
|
+
loader: "postcss-loader",
|
|
1195
1274
|
options: { plugins: () => [postcssPresetEnv({ stage: 0 })] },
|
|
1196
1275
|
},
|
|
1197
1276
|
// Can be `less-loader`
|
|
1198
1277
|
{
|
|
1199
|
-
loader:
|
|
1278
|
+
loader: "sass-loader",
|
|
1200
1279
|
},
|
|
1201
1280
|
],
|
|
1202
1281
|
},
|
|
1282
|
+
// For webpack v5
|
|
1203
1283
|
{
|
|
1204
1284
|
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
limit: 8192,
|
|
1208
|
-
},
|
|
1285
|
+
// More information here https://webpack.js.org/guides/asset-modules/
|
|
1286
|
+
type: "asset",
|
|
1209
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
|
+
// },
|
|
1210
1296
|
],
|
|
1211
1297
|
},
|
|
1212
1298
|
};
|
|
@@ -1230,15 +1316,15 @@ module.exports = {
|
|
|
1230
1316
|
rules: [
|
|
1231
1317
|
{
|
|
1232
1318
|
test: /\.css$/i,
|
|
1233
|
-
use: [
|
|
1319
|
+
use: ["style-loader", "css-loader"],
|
|
1234
1320
|
},
|
|
1235
1321
|
],
|
|
1236
1322
|
},
|
|
1237
1323
|
resolve: {
|
|
1238
1324
|
alias: {
|
|
1239
|
-
|
|
1325
|
+
"/assets/unresolved/img.png": path.resolve(
|
|
1240
1326
|
__dirname,
|
|
1241
|
-
|
|
1327
|
+
"assets/real-path-to-img/img.png"
|
|
1242
1328
|
),
|
|
1243
1329
|
},
|
|
1244
1330
|
},
|
|
@@ -1326,7 +1412,7 @@ $colorBackground: red;
|
|
|
1326
1412
|
File treated as `CSS Module`.
|
|
1327
1413
|
|
|
1328
1414
|
```scss
|
|
1329
|
-
@import
|
|
1415
|
+
@import "variables.scss";
|
|
1330
1416
|
.componentClass {
|
|
1331
1417
|
background-color: $colorBackground;
|
|
1332
1418
|
}
|
|
@@ -1337,8 +1423,8 @@ File treated as `CSS Module`.
|
|
|
1337
1423
|
Using both `CSS Module` functionality as well as SCSS variables directly in JavaScript.
|
|
1338
1424
|
|
|
1339
1425
|
```jsx
|
|
1340
|
-
import svars from
|
|
1341
|
-
import styles from
|
|
1426
|
+
import svars from "variables.scss";
|
|
1427
|
+
import styles from "Component.module.scss";
|
|
1342
1428
|
|
|
1343
1429
|
// Render DOM with CSS modules class name
|
|
1344
1430
|
// <div className={styles.componentClass}>
|