css-loader 4.2.2 → 5.0.2
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 +46 -0
- package/README.md +120 -86
- 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 +3 -4
- package/dist/plugins/postcss-icss-parser.js +101 -96
- package/dist/plugins/postcss-import-parser.js +189 -183
- package/dist/plugins/postcss-url-parser.js +199 -195
- 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 +126 -96
- package/package.json +37 -36
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,52 @@
|
|
|
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.0.2](https://github.com/webpack-contrib/css-loader/compare/v5.0.1...v5.0.2) (2021-02-08)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* 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))
|
|
11
|
+
|
|
12
|
+
### [5.0.1](https://github.com/webpack-contrib/css-loader/compare/v5.0.0...v5.0.1) (2020-11-04)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* 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))
|
|
18
|
+
|
|
19
|
+
## [5.0.0](https://github.com/webpack-contrib/css-loader/compare/v4.3.0...v5.0.0) (2020-10-13)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### ⚠ BREAKING CHANGES
|
|
23
|
+
|
|
24
|
+
* migrate on PostCSS 8
|
|
25
|
+
* runtime doesn't contain source maps code without `sourceMap: true`
|
|
26
|
+
* returned value from the `getLocalIdent` escapes by default, the `exportName` value is always unescaped
|
|
27
|
+
* Auto enable icss modules for all files for which `/\.icss\.\w+$/i` (the `modules.compileType` option is `icss`)
|
|
28
|
+
* `[emoji]` placeholder was deprecated
|
|
29
|
+
* `icss` option was removed (it was deprecated previously)
|
|
30
|
+
|
|
31
|
+
### Features
|
|
32
|
+
|
|
33
|
+
* allow named exports to have underscores in names ([#1209](https://github.com/webpack-contrib/css-loader/issues/1209)) ([747d62b](https://github.com/webpack-contrib/css-loader/commit/747d62b75a878d8881f4819b96297667dc689b8f))
|
|
34
|
+
* hide warning when you don't need handle `url()`/`@import` ([#1195](https://github.com/webpack-contrib/css-loader/issues/1195)) ([dd52931](https://github.com/webpack-contrib/css-loader/commit/dd52931150ed42f122d9017642437c26cc1b2422))
|
|
35
|
+
* improve error message ([52412f6](https://github.com/webpack-contrib/css-loader/commit/52412f6d5a54745ee37a4a67f038455c26ba5772))
|
|
36
|
+
* reduce runtime ([9f974be](https://github.com/webpack-contrib/css-loader/commit/9f974be81f5942d3afaf783529677bd541952fa3))
|
|
37
|
+
* add fallback if custom getLocalIdent returns `null`/`undefined` ([#1193](https://github.com/webpack-contrib/css-loader/issues/1193)) ([0f95841](https://github.com/webpack-contrib/css-loader/commit/0f9584135e63f9f354043e7f414e0c1aad0edc6e))
|
|
38
|
+
|
|
39
|
+
## [4.3.0](https://github.com/webpack-contrib/css-loader/compare/v4.2.2...v4.3.0) (2020-09-08)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Features
|
|
43
|
+
|
|
44
|
+
* the `importLoaders` can be `string` ([#1178](https://github.com/webpack-contrib/css-loader/issues/1178)) ([ec58a7c](https://github.com/webpack-contrib/css-loader/commit/ec58a7cfda46443e35539d66b86685195fa5db03))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### Bug Fixes
|
|
48
|
+
|
|
49
|
+
* line breaks in `url` function ([88b8ddc](https://github.com/webpack-contrib/css-loader/commit/88b8ddc1d78a2b6a917ed2dfe2f2a37cf6a84190))
|
|
50
|
+
|
|
5
51
|
### [4.2.2](https://github.com/webpack-contrib/css-loader/compare/v4.2.1...v4.2.2) (2020-08-24)
|
|
6
52
|
|
|
7
53
|
|
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
|
],
|
|
@@ -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
|
},
|
|
@@ -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
|
},
|
|
@@ -1131,6 +1136,8 @@ module.exports = {
|
|
|
1131
1136
|
|
|
1132
1137
|
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
1138
|
|
|
1139
|
+
**For webpack v5:**
|
|
1140
|
+
|
|
1134
1141
|
**webpack.config.js**
|
|
1135
1142
|
|
|
1136
1143
|
```js
|
|
@@ -1139,11 +1146,33 @@ module.exports = {
|
|
|
1139
1146
|
rules: [
|
|
1140
1147
|
{
|
|
1141
1148
|
test: /\.css$/i,
|
|
1142
|
-
use: [
|
|
1149
|
+
use: ["style-loader", "css-loader"],
|
|
1143
1150
|
},
|
|
1144
1151
|
{
|
|
1145
1152
|
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
|
|
1146
|
-
|
|
1153
|
+
// More information here https://webpack.js.org/guides/asset-modules/
|
|
1154
|
+
type: "asset",
|
|
1155
|
+
},
|
|
1156
|
+
],
|
|
1157
|
+
},
|
|
1158
|
+
};
|
|
1159
|
+
```
|
|
1160
|
+
|
|
1161
|
+
**For webpack v4:**
|
|
1162
|
+
|
|
1163
|
+
**webpack.config.js**
|
|
1164
|
+
|
|
1165
|
+
```js
|
|
1166
|
+
module.exports = {
|
|
1167
|
+
module: {
|
|
1168
|
+
rules: [
|
|
1169
|
+
{
|
|
1170
|
+
test: /\.css$/i,
|
|
1171
|
+
use: ["style-loader", "css-loader"],
|
|
1172
|
+
},
|
|
1173
|
+
{
|
|
1174
|
+
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
|
|
1175
|
+
loader: "url-loader",
|
|
1147
1176
|
options: {
|
|
1148
1177
|
limit: 8192,
|
|
1149
1178
|
},
|
|
@@ -1177,34 +1206,39 @@ module.exports = {
|
|
|
1177
1206
|
// For Less - /\.((c|le)ss)$/i,
|
|
1178
1207
|
test: /\.((c|sa|sc)ss)$/i,
|
|
1179
1208
|
use: [
|
|
1180
|
-
|
|
1209
|
+
"style-loader",
|
|
1181
1210
|
{
|
|
1182
|
-
loader:
|
|
1211
|
+
loader: "css-loader",
|
|
1183
1212
|
options: {
|
|
1184
1213
|
// Run `postcss-loader` on each CSS `@import`, do not forget that `sass-loader` compile non CSS `@import`'s into a single file
|
|
1185
1214
|
// If you need run `sass-loader` and `postcss-loader` on each CSS `@import` please set it to `2`
|
|
1186
1215
|
importLoaders: 1,
|
|
1187
|
-
// Automatically enable css modules for files satisfying `/\.module\.\w+$/i` RegExp.
|
|
1188
|
-
modules: { auto: true },
|
|
1189
1216
|
},
|
|
1190
1217
|
},
|
|
1191
1218
|
{
|
|
1192
|
-
loader:
|
|
1219
|
+
loader: "postcss-loader",
|
|
1193
1220
|
options: { plugins: () => [postcssPresetEnv({ stage: 0 })] },
|
|
1194
1221
|
},
|
|
1195
1222
|
// Can be `less-loader`
|
|
1196
1223
|
{
|
|
1197
|
-
loader:
|
|
1224
|
+
loader: "sass-loader",
|
|
1198
1225
|
},
|
|
1199
1226
|
],
|
|
1200
1227
|
},
|
|
1228
|
+
// For webpack v5
|
|
1201
1229
|
{
|
|
1202
1230
|
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
limit: 8192,
|
|
1206
|
-
},
|
|
1231
|
+
// More information here https://webpack.js.org/guides/asset-modules/
|
|
1232
|
+
type: "asset",
|
|
1207
1233
|
},
|
|
1234
|
+
// For webpack v4
|
|
1235
|
+
// {
|
|
1236
|
+
// test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
|
|
1237
|
+
// loader: "url-loader",
|
|
1238
|
+
// options: {
|
|
1239
|
+
// limit: 8192,
|
|
1240
|
+
// },
|
|
1241
|
+
// },
|
|
1208
1242
|
],
|
|
1209
1243
|
},
|
|
1210
1244
|
};
|
|
@@ -1228,15 +1262,15 @@ module.exports = {
|
|
|
1228
1262
|
rules: [
|
|
1229
1263
|
{
|
|
1230
1264
|
test: /\.css$/i,
|
|
1231
|
-
use: [
|
|
1265
|
+
use: ["style-loader", "css-loader"],
|
|
1232
1266
|
},
|
|
1233
1267
|
],
|
|
1234
1268
|
},
|
|
1235
1269
|
resolve: {
|
|
1236
1270
|
alias: {
|
|
1237
|
-
|
|
1271
|
+
"/assets/unresolved/img.png": path.resolve(
|
|
1238
1272
|
__dirname,
|
|
1239
|
-
|
|
1273
|
+
"assets/real-path-to-img/img.png"
|
|
1240
1274
|
),
|
|
1241
1275
|
},
|
|
1242
1276
|
},
|
|
@@ -1245,7 +1279,7 @@ module.exports = {
|
|
|
1245
1279
|
|
|
1246
1280
|
### Separating `Interoperable CSS`-only and `CSS Module` features
|
|
1247
1281
|
|
|
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.
|
|
1282
|
+
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
1283
|
Meanwhile all files matching `*.module.scss` are treated as `CSS Modules` in this example.
|
|
1250
1284
|
|
|
1251
1285
|
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 +1358,7 @@ $colorBackground: red;
|
|
|
1324
1358
|
File treated as `CSS Module`.
|
|
1325
1359
|
|
|
1326
1360
|
```scss
|
|
1327
|
-
@import
|
|
1361
|
+
@import "variables.scss";
|
|
1328
1362
|
.componentClass {
|
|
1329
1363
|
background-color: $colorBackground;
|
|
1330
1364
|
}
|
|
@@ -1335,8 +1369,8 @@ File treated as `CSS Module`.
|
|
|
1335
1369
|
Using both `CSS Module` functionality as well as SCSS variables directly in JavaScript.
|
|
1336
1370
|
|
|
1337
1371
|
```jsx
|
|
1338
|
-
import svars from
|
|
1339
|
-
import styles from
|
|
1372
|
+
import svars from "variables.scss";
|
|
1373
|
+
import styles from "Component.module.scss";
|
|
1340
1374
|
|
|
1341
1375
|
// Render DOM with CSS modules class name
|
|
1342
1376
|
// <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
|
|
package/dist/Warning.js
CHANGED
|
@@ -13,12 +13,12 @@ class Warning extends Error {
|
|
|
13
13
|
line,
|
|
14
14
|
column
|
|
15
15
|
} = warning;
|
|
16
|
-
this.name =
|
|
16
|
+
this.name = "Warning"; // Based on https://github.com/postcss/postcss/blob/master/lib/warning.es6#L74
|
|
17
17
|
// We don't need `plugin` properties.
|
|
18
18
|
|
|
19
19
|
this.message = `${this.name}\n\n`;
|
|
20
20
|
|
|
21
|
-
if (typeof line !==
|
|
21
|
+
if (typeof line !== "undefined") {
|
|
22
22
|
this.message += `(${line}:${column}) `;
|
|
23
23
|
}
|
|
24
24
|
|