css-loader 3.6.0 → 4.2.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 +63 -0
- package/README.md +221 -103
- package/dist/index.js +104 -73
- package/dist/options.json +48 -25
- package/dist/plugins/postcss-icss-parser.js +73 -60
- package/dist/plugins/postcss-import-parser.js +124 -51
- package/dist/plugins/postcss-url-parser.js +202 -106
- package/dist/utils.js +264 -115
- package/package.json +23 -21
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,69 @@
|
|
|
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
|
+
## [4.2.0](https://github.com/webpack-contrib/css-loader/compare/v4.1.1...v4.2.0) (2020-07-31)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add `module.type` option, the `icss` option is deprecated ([#1150](https://github.com/webpack-contrib/css-loader/issues/1150)) ([68f72af](https://github.com/webpack-contrib/css-loader/commit/68f72af2a09111f74dcacbf7af019fe7eb40cb6c))
|
|
11
|
+
|
|
12
|
+
### [4.1.1](https://github.com/webpack-contrib/css-loader/compare/v4.1.0...v4.1.1) (2020-07-30)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* remove unnecessary `console` call ([#1148](https://github.com/webpack-contrib/css-loader/issues/1148)) ([b1b90ca](https://github.com/webpack-contrib/css-loader/commit/b1b90caaea8eb045177749729340c7906454a84b))
|
|
18
|
+
|
|
19
|
+
## [4.1.0](https://github.com/webpack-contrib/css-loader/compare/v4.0.0...v4.1.0) (2020-07-29)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* add `icss` option ([#1140](https://github.com/webpack-contrib/css-loader/issues/1140)) ([a8ec7da](https://github.com/webpack-contrib/css-loader/commit/a8ec7da42234e0b2eb061d2a920669940bcbdf05))
|
|
25
|
+
* support absolute paths ([f9ba0ce](https://github.com/webpack-contrib/css-loader/commit/f9ba0ce11789770c4c9220478e9c98dbd432a5d6))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* do not crash with `data` URLs ([#1142](https://github.com/webpack-contrib/css-loader/issues/1142)) ([91bc64b](https://github.com/webpack-contrib/css-loader/commit/91bc64b81abfeffd174639a8fdf2366412c11426))
|
|
31
|
+
* performance ([#1144](https://github.com/webpack-contrib/css-loader/issues/1144)) ([4f1baa2](https://github.com/webpack-contrib/css-loader/commit/4f1baa211eb27b0b281ba9f262fa12e8aaefc0ba))
|
|
32
|
+
|
|
33
|
+
## [4.0.0](https://github.com/webpack-contrib/css-loader/compare/v3.6.0...v4.0.0) (2020-07-25)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### ⚠ BREAKING CHANGES
|
|
37
|
+
|
|
38
|
+
* minimum required `Node.js` version is `10.13.0`
|
|
39
|
+
* minimum required `webpack` version is `4.27.0`
|
|
40
|
+
* the `esModule` option is `true` by default
|
|
41
|
+
* default value of the `sourceMap` option depends on the `devtool` option
|
|
42
|
+
* `icss` plugin disable by default, you need to setup the `modules` option to enable it
|
|
43
|
+
* the `modules` option is `true` by default for all files matching `/\.module\.\w+$/i.test(filename)` regular expression, `module.auto` is `true` by default
|
|
44
|
+
* the `modules.context` option was renamed to the `modules.localIdentContext` option
|
|
45
|
+
* default the `modules.localIdentContext` value is `compiler.context` for the `module.getLocalIdent` option
|
|
46
|
+
* the `modules.hashPrefix` option was renamed to the `modules.localIdentHashPrefix` option
|
|
47
|
+
* the `localsConvention` option was moved and renamed to the `modules.exportLocalsConvention` option
|
|
48
|
+
* the `getLocalIndent` option should be always `Function` and should always return `String` value
|
|
49
|
+
* the `onlyLocals` option was moved and renamed to the `modules.exportOnlyLocals` option
|
|
50
|
+
* function arguments of the `import` option were changed, it is now `function(url, media, resourcePath) {}`
|
|
51
|
+
* inline syntax was changed, please write `~` before the file request, i.e. rewrite `url(~!!loader!package/img.png)` to `url(!!loader!~package/img.png)`
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### Features
|
|
55
|
+
|
|
56
|
+
* `@value` supports importing `url()` ([#1126](https://github.com/webpack-contrib/css-loader/issues/1126)) ([7f49a0a](https://github.com/webpack-contrib/css-loader/commit/7f49a0a6047846bb2e432558365e19d4a0dfb366))
|
|
57
|
+
* improve `url()` resolving algorithm ([bc19ddd](https://github.com/webpack-contrib/css-loader/commit/bc19ddd8779dafbc2a420870a3cb841041ce9c7c))
|
|
58
|
+
* named export for locals ([#1108](https://github.com/webpack-contrib/css-loader/issues/1108)) ([d139ec1](https://github.com/webpack-contrib/css-loader/commit/d139ec1d763f9944550b31f2a75183e488dd1224))
|
|
59
|
+
* respected the `style` field from package.json ([#1099](https://github.com/webpack-contrib/css-loader/issues/1099)) ([edf5347](https://github.com/webpack-contrib/css-loader/commit/edf5347e4203a62e50b87248a83da198afdc6eba))
|
|
60
|
+
* support `file:` protocol ([5604205](https://github.com/webpack-contrib/css-loader/commit/560420567eb0e1a635648b7f4ff0365db475384c))
|
|
61
|
+
* support server relative URLs
|
|
62
|
+
|
|
63
|
+
### Bug Fixes
|
|
64
|
+
|
|
65
|
+
* resolution algorithm, you don't need `~` inside packages in `node_modules` ([76f1480](https://github.com/webpack-contrib/css-loader/commit/76f1480b14265369ac5dc8dbbce467cfb8e814c5))
|
|
66
|
+
|
|
67
|
+
|
|
5
68
|
## [3.6.0](https://github.com/webpack-contrib/css-loader/compare/v3.5.3...v3.6.0) (2020-06-13)
|
|
6
69
|
|
|
7
70
|
|
package/README.md
CHANGED
|
@@ -109,16 +109,14 @@ module.exports = {
|
|
|
109
109
|
|
|
110
110
|
## Options
|
|
111
111
|
|
|
112
|
-
|
|
|
113
|
-
|
|
|
114
|
-
|
|
|
115
|
-
|
|
|
116
|
-
|
|
|
117
|
-
|
|
|
118
|
-
|
|
|
119
|
-
|
|
|
120
|
-
| **[`onlyLocals`](#onlylocals)** | `{Boolean}` | `false` | Export only locals |
|
|
121
|
-
| **[`esModule`](#esmodule)** | `{Boolean}` | `false` | Use ES modules syntax |
|
|
112
|
+
| Name | Type | Default | Description |
|
|
113
|
+
| :-----------------------------------: | :-------------------------: | :----------------: | :--------------------------------------------------------------------- |
|
|
114
|
+
| **[`url`](#url)** | `{Boolean\|Function}` | `true` | Enables/Disables `url`/`image-set` functions handling |
|
|
115
|
+
| **[`import`](#import)** | `{Boolean\|Function}` | `true` | Enables/Disables `@import` at-rules handling |
|
|
116
|
+
| **[`modules`](#modules)** | `{Boolean\|String\|Object}` | `{auto: true}` | Enables/Disables CSS Modules and their configuration |
|
|
117
|
+
| **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps |
|
|
118
|
+
| **[`importLoaders`](#importloaders)** | `{Number}` | `0` | Enables/Disables or setups number of loaders applied before CSS loader |
|
|
119
|
+
| **[`esModule`](#esmodule)** | `{Boolean}` | `true` | Use ES modules syntax |
|
|
122
120
|
|
|
123
121
|
### `url`
|
|
124
122
|
|
|
@@ -126,7 +124,7 @@ Type: `Boolean|Function`
|
|
|
126
124
|
Default: `true`
|
|
127
125
|
|
|
128
126
|
Enables/Disables `url`/`image-set` functions handling.
|
|
129
|
-
Control `url()` resolving. Absolute URLs
|
|
127
|
+
Control `url()` resolving. Absolute URLs are not resolving.
|
|
130
128
|
|
|
131
129
|
Examples resolutions:
|
|
132
130
|
|
|
@@ -264,13 +262,11 @@ module.exports = {
|
|
|
264
262
|
test: /\.css$/i,
|
|
265
263
|
loader: 'css-loader',
|
|
266
264
|
options: {
|
|
267
|
-
import: (
|
|
268
|
-
// parsedImport.url - url of `@import`
|
|
269
|
-
// parsedImport.media - media query of `@import`
|
|
265
|
+
import: (url, media, resourcePath) => {
|
|
270
266
|
// resourcePath - path to css file
|
|
271
267
|
|
|
272
268
|
// Don't handle `style.css` import
|
|
273
|
-
if (
|
|
269
|
+
if (url.includes('style.css')) {
|
|
274
270
|
return false;
|
|
275
271
|
}
|
|
276
272
|
|
|
@@ -286,7 +282,7 @@ module.exports = {
|
|
|
286
282
|
### `modules`
|
|
287
283
|
|
|
288
284
|
Type: `Boolean|String|Object`
|
|
289
|
-
Default: `
|
|
285
|
+
Default: based on filename, `true` for all files matching `/\.module\.\w+$/i.test(filename)` regular expression, more information you can read [here](https://github.com/webpack-contrib/css-loader#auto)
|
|
290
286
|
|
|
291
287
|
Enables/Disables CSS Modules and their configuration.
|
|
292
288
|
|
|
@@ -415,6 +411,8 @@ exports.locals = {
|
|
|
415
411
|
|
|
416
412
|
To import a local classname from another module.
|
|
417
413
|
|
|
414
|
+
> i We strongly recommend that you specify the extension when importing a file, since it is possible to import a file with any extension and it is not known in advance which file to use.
|
|
415
|
+
|
|
418
416
|
```css
|
|
419
417
|
:local(.continueButton) {
|
|
420
418
|
composes: button from 'library/button.css';
|
|
@@ -527,11 +525,48 @@ module.exports = {
|
|
|
527
525
|
loader: 'css-loader',
|
|
528
526
|
options: {
|
|
529
527
|
modules: {
|
|
528
|
+
compileType: 'module',
|
|
530
529
|
mode: 'local',
|
|
530
|
+
auto: true,
|
|
531
531
|
exportGlobals: true,
|
|
532
532
|
localIdentName: '[path][name]__[local]--[hash:base64:5]',
|
|
533
533
|
context: path.resolve(__dirname, 'src'),
|
|
534
|
-
|
|
534
|
+
localIdentHashPrefix: 'my-custom-hash',
|
|
535
|
+
namedExport: true,
|
|
536
|
+
exportLocalsConvention: 'camelCase',
|
|
537
|
+
exportOnlyLocals: false,
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
},
|
|
541
|
+
],
|
|
542
|
+
},
|
|
543
|
+
};
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
##### `compileType`
|
|
547
|
+
|
|
548
|
+
Type: `'module' | 'icss'`
|
|
549
|
+
Default: `'module'`
|
|
550
|
+
|
|
551
|
+
Controls the level of compilation applied to the input styles.
|
|
552
|
+
|
|
553
|
+
The `module` handles `class` and `id` scoping and `@value` values.
|
|
554
|
+
The `icss` will only compile the low level `Interoperable CSS` format for declaring `:import` and `:export` dependencies between CSS and other languages.
|
|
555
|
+
|
|
556
|
+
ICSS underpins CSS Module support, and provides a low level syntax for other tools to implement CSS-module variations of their own.
|
|
557
|
+
|
|
558
|
+
**webpack.config.js**
|
|
559
|
+
|
|
560
|
+
```js
|
|
561
|
+
module.exports = {
|
|
562
|
+
module: {
|
|
563
|
+
rules: [
|
|
564
|
+
{
|
|
565
|
+
test: /\.css$/i,
|
|
566
|
+
loader: 'css-loader',
|
|
567
|
+
options: {
|
|
568
|
+
modules: {
|
|
569
|
+
compileType: 'icss',
|
|
535
570
|
},
|
|
536
571
|
},
|
|
537
572
|
},
|
|
@@ -543,9 +578,9 @@ module.exports = {
|
|
|
543
578
|
##### `auto`
|
|
544
579
|
|
|
545
580
|
Type: `Boolean|RegExp|Function`
|
|
546
|
-
Default: `'
|
|
581
|
+
Default: `'true'`
|
|
547
582
|
|
|
548
|
-
Allows auto enable
|
|
583
|
+
Allows auto enable CSS modules based on filename.
|
|
549
584
|
|
|
550
585
|
###### `Boolean`
|
|
551
586
|
|
|
@@ -690,39 +725,12 @@ module.exports = {
|
|
|
690
725
|
};
|
|
691
726
|
```
|
|
692
727
|
|
|
693
|
-
##### `exportGlobals`
|
|
694
|
-
|
|
695
|
-
Type: `Boolean`
|
|
696
|
-
Default: `false`
|
|
697
|
-
|
|
698
|
-
Allow `css-loader` to export names from global class or id, so you can use that as local name.
|
|
699
|
-
|
|
700
|
-
**webpack.config.js**
|
|
701
|
-
|
|
702
|
-
```js
|
|
703
|
-
module.exports = {
|
|
704
|
-
module: {
|
|
705
|
-
rules: [
|
|
706
|
-
{
|
|
707
|
-
test: /\.css$/i,
|
|
708
|
-
loader: 'css-loader',
|
|
709
|
-
options: {
|
|
710
|
-
modules: {
|
|
711
|
-
exportGlobals: true,
|
|
712
|
-
},
|
|
713
|
-
},
|
|
714
|
-
},
|
|
715
|
-
],
|
|
716
|
-
},
|
|
717
|
-
};
|
|
718
|
-
```
|
|
719
|
-
|
|
720
728
|
##### `localIdentName`
|
|
721
729
|
|
|
722
730
|
Type: `String`
|
|
723
731
|
Default: `'[hash:base64]'`
|
|
724
732
|
|
|
725
|
-
|
|
733
|
+
Allows to configure the generated local ident name.
|
|
726
734
|
See [loader-utils's documentation](https://github.com/webpack/loader-utils#interpolatename) for more information on options.
|
|
727
735
|
|
|
728
736
|
Recommendations:
|
|
@@ -754,13 +762,12 @@ module.exports = {
|
|
|
754
762
|
};
|
|
755
763
|
```
|
|
756
764
|
|
|
757
|
-
##### `
|
|
765
|
+
##### `localIdentContext`
|
|
758
766
|
|
|
759
767
|
Type: `String`
|
|
760
|
-
Default: `
|
|
768
|
+
Default: `compiler.context`
|
|
761
769
|
|
|
762
|
-
|
|
763
|
-
By default we use `rootContext` of loader.
|
|
770
|
+
Allows to redefine basic loader context for local ident name.
|
|
764
771
|
|
|
765
772
|
**webpack.config.js**
|
|
766
773
|
|
|
@@ -782,12 +789,12 @@ module.exports = {
|
|
|
782
789
|
};
|
|
783
790
|
```
|
|
784
791
|
|
|
785
|
-
##### `
|
|
792
|
+
##### `localIdentHashPrefix`
|
|
786
793
|
|
|
787
794
|
Type: `String`
|
|
788
795
|
Default: `undefined`
|
|
789
796
|
|
|
790
|
-
|
|
797
|
+
Allows to add custom hash to generate more unique classes.
|
|
791
798
|
|
|
792
799
|
**webpack.config.js**
|
|
793
800
|
|
|
@@ -800,7 +807,7 @@ module.exports = {
|
|
|
800
807
|
loader: 'css-loader',
|
|
801
808
|
options: {
|
|
802
809
|
modules: {
|
|
803
|
-
|
|
810
|
+
localIdentHashPrefix: 'hash',
|
|
804
811
|
},
|
|
805
812
|
},
|
|
806
813
|
},
|
|
@@ -809,14 +816,11 @@ module.exports = {
|
|
|
809
816
|
};
|
|
810
817
|
```
|
|
811
818
|
|
|
812
|
-
##### `
|
|
819
|
+
##### `localIdentRegExp`
|
|
813
820
|
|
|
814
|
-
Type: `
|
|
821
|
+
Type: `String|RegExp`
|
|
815
822
|
Default: `undefined`
|
|
816
823
|
|
|
817
|
-
You can also specify the absolute path to your custom `getLocalIdent` function to generate classname based on a different schema.
|
|
818
|
-
By default we use built-in function to generate a classname.
|
|
819
|
-
|
|
820
824
|
**webpack.config.js**
|
|
821
825
|
|
|
822
826
|
```js
|
|
@@ -828,9 +832,7 @@ module.exports = {
|
|
|
828
832
|
loader: 'css-loader',
|
|
829
833
|
options: {
|
|
830
834
|
modules: {
|
|
831
|
-
|
|
832
|
-
return 'whatever_random_class_name';
|
|
833
|
-
},
|
|
835
|
+
localIdentRegExp: /page-(.*)\.css/i,
|
|
834
836
|
},
|
|
835
837
|
},
|
|
836
838
|
},
|
|
@@ -839,11 +841,14 @@ module.exports = {
|
|
|
839
841
|
};
|
|
840
842
|
```
|
|
841
843
|
|
|
842
|
-
##### `
|
|
844
|
+
##### `getLocalIdent`
|
|
843
845
|
|
|
844
|
-
Type: `
|
|
846
|
+
Type: `Function`
|
|
845
847
|
Default: `undefined`
|
|
846
848
|
|
|
849
|
+
Allows to specify a function to generate the classname.
|
|
850
|
+
By default we use built-in function to generate a classname.
|
|
851
|
+
|
|
847
852
|
**webpack.config.js**
|
|
848
853
|
|
|
849
854
|
```js
|
|
@@ -855,7 +860,9 @@ module.exports = {
|
|
|
855
860
|
loader: 'css-loader',
|
|
856
861
|
options: {
|
|
857
862
|
modules: {
|
|
858
|
-
|
|
863
|
+
getLocalIdent: (context, localIdentName, localName, options) => {
|
|
864
|
+
return 'whatever_random_class_name';
|
|
865
|
+
},
|
|
859
866
|
},
|
|
860
867
|
},
|
|
861
868
|
},
|
|
@@ -864,16 +871,37 @@ module.exports = {
|
|
|
864
871
|
};
|
|
865
872
|
```
|
|
866
873
|
|
|
867
|
-
|
|
874
|
+
##### `namedExport`
|
|
868
875
|
|
|
869
876
|
Type: `Boolean`
|
|
870
877
|
Default: `false`
|
|
871
878
|
|
|
872
|
-
Enables/
|
|
879
|
+
Enables/disables ES modules named export for locals.
|
|
880
|
+
|
|
881
|
+
> ⚠ Names of locals are converted to camelcase, i.e. the `exportLocalsConvention` option has `camelCaseOnly` value by default.
|
|
873
882
|
|
|
874
|
-
|
|
883
|
+
> ⚠ It is not allowed to use JavaScript reserved words in css class names.
|
|
875
884
|
|
|
876
|
-
|
|
885
|
+
**styles.css**
|
|
886
|
+
|
|
887
|
+
```css
|
|
888
|
+
.foo-baz {
|
|
889
|
+
color: red;
|
|
890
|
+
}
|
|
891
|
+
.bar {
|
|
892
|
+
color: blue;
|
|
893
|
+
}
|
|
894
|
+
```
|
|
895
|
+
|
|
896
|
+
**index.js**
|
|
897
|
+
|
|
898
|
+
```js
|
|
899
|
+
import { fooBaz, bar } from './styles.css';
|
|
900
|
+
|
|
901
|
+
console.log(fooBaz, bar);
|
|
902
|
+
```
|
|
903
|
+
|
|
904
|
+
You can enable a ES module named export using:
|
|
877
905
|
|
|
878
906
|
**webpack.config.js**
|
|
879
907
|
|
|
@@ -885,7 +913,10 @@ module.exports = {
|
|
|
885
913
|
test: /\.css$/i,
|
|
886
914
|
loader: 'css-loader',
|
|
887
915
|
options: {
|
|
888
|
-
|
|
916
|
+
esModule: true,
|
|
917
|
+
modules: {
|
|
918
|
+
namedExport: true,
|
|
919
|
+
},
|
|
889
920
|
},
|
|
890
921
|
},
|
|
891
922
|
],
|
|
@@ -893,14 +924,12 @@ module.exports = {
|
|
|
893
924
|
};
|
|
894
925
|
```
|
|
895
926
|
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
Type: `Number`
|
|
899
|
-
Default: `0`
|
|
927
|
+
##### `exportGlobals`
|
|
900
928
|
|
|
901
|
-
|
|
929
|
+
Type: `Boolean`
|
|
930
|
+
Default: `false`
|
|
902
931
|
|
|
903
|
-
|
|
932
|
+
Allow `css-loader` to export names from global class or id, so you can use that as local name.
|
|
904
933
|
|
|
905
934
|
**webpack.config.js**
|
|
906
935
|
|
|
@@ -910,37 +939,29 @@ module.exports = {
|
|
|
910
939
|
rules: [
|
|
911
940
|
{
|
|
912
941
|
test: /\.css$/i,
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
{
|
|
916
|
-
|
|
917
|
-
options: {
|
|
918
|
-
importLoaders: 2,
|
|
919
|
-
// 0 => no loaders (default);
|
|
920
|
-
// 1 => postcss-loader;
|
|
921
|
-
// 2 => postcss-loader, sass-loader
|
|
922
|
-
},
|
|
942
|
+
loader: 'css-loader',
|
|
943
|
+
options: {
|
|
944
|
+
modules: {
|
|
945
|
+
exportGlobals: true,
|
|
923
946
|
},
|
|
924
|
-
|
|
925
|
-
'sass-loader',
|
|
926
|
-
],
|
|
947
|
+
},
|
|
927
948
|
},
|
|
928
949
|
],
|
|
929
950
|
},
|
|
930
951
|
};
|
|
931
952
|
```
|
|
932
953
|
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
### `localsConvention`
|
|
954
|
+
##### `exportlocalsConvention`
|
|
936
955
|
|
|
937
956
|
Type: `String`
|
|
938
|
-
Default: `
|
|
957
|
+
Default: based on the `modules.namedExport` option value, if `true` - `camelCaseOnly`, otherwise `asIs`
|
|
939
958
|
|
|
940
|
-
Style of exported
|
|
959
|
+
Style of exported class names.
|
|
941
960
|
|
|
942
961
|
By default, the exported JSON keys mirror the class names (i.e `asIs` value).
|
|
943
962
|
|
|
963
|
+
> ⚠ Only `camelCaseOnly` value allowed if you set the `namedExport` value to `true`.
|
|
964
|
+
|
|
944
965
|
| Name | Type | Description |
|
|
945
966
|
| :-------------------: | :--------: | :----------------------------------------------------------------------------------------------- |
|
|
946
967
|
| **`'asIs'`** | `{String}` | Class names will be exported as is. |
|
|
@@ -972,6 +993,7 @@ module.exports = {
|
|
|
972
993
|
test: /\.css$/i,
|
|
973
994
|
loader: 'css-loader',
|
|
974
995
|
options: {
|
|
996
|
+
mode: 'local',
|
|
975
997
|
localsConvention: 'camelCase',
|
|
976
998
|
},
|
|
977
999
|
},
|
|
@@ -980,7 +1002,7 @@ module.exports = {
|
|
|
980
1002
|
};
|
|
981
1003
|
```
|
|
982
1004
|
|
|
983
|
-
|
|
1005
|
+
##### `exportOnlyLocals`
|
|
984
1006
|
|
|
985
1007
|
Type: `Boolean`
|
|
986
1008
|
Default: `false`
|
|
@@ -1001,7 +1023,9 @@ module.exports = {
|
|
|
1001
1023
|
test: /\.css$/i,
|
|
1002
1024
|
loader: 'css-loader',
|
|
1003
1025
|
options: {
|
|
1004
|
-
|
|
1026
|
+
modules: {
|
|
1027
|
+
exportOnlyLocals: true,
|
|
1028
|
+
},
|
|
1005
1029
|
},
|
|
1006
1030
|
},
|
|
1007
1031
|
],
|
|
@@ -1009,15 +1033,79 @@ module.exports = {
|
|
|
1009
1033
|
};
|
|
1010
1034
|
```
|
|
1011
1035
|
|
|
1036
|
+
### `sourceMap`
|
|
1037
|
+
|
|
1038
|
+
Type: `Boolean`
|
|
1039
|
+
Default: depends on the `compiler.devtool` value
|
|
1040
|
+
|
|
1041
|
+
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.
|
|
1042
|
+
|
|
1043
|
+
**webpack.config.js**
|
|
1044
|
+
|
|
1045
|
+
```js
|
|
1046
|
+
module.exports = {
|
|
1047
|
+
module: {
|
|
1048
|
+
rules: [
|
|
1049
|
+
{
|
|
1050
|
+
test: /\.css$/i,
|
|
1051
|
+
loader: 'css-loader',
|
|
1052
|
+
options: {
|
|
1053
|
+
sourceMap: true,
|
|
1054
|
+
},
|
|
1055
|
+
},
|
|
1056
|
+
],
|
|
1057
|
+
},
|
|
1058
|
+
};
|
|
1059
|
+
```
|
|
1060
|
+
|
|
1061
|
+
### `importLoaders`
|
|
1062
|
+
|
|
1063
|
+
Type: `Number`
|
|
1064
|
+
Default: `0`
|
|
1065
|
+
|
|
1066
|
+
Enables/Disables or setups number of loaders applied before CSS loader.
|
|
1067
|
+
|
|
1068
|
+
The option `importLoaders` allows you to configure how many loaders before `css-loader` should be applied to `@import`ed resources.
|
|
1069
|
+
|
|
1070
|
+
**webpack.config.js**
|
|
1071
|
+
|
|
1072
|
+
```js
|
|
1073
|
+
module.exports = {
|
|
1074
|
+
module: {
|
|
1075
|
+
rules: [
|
|
1076
|
+
{
|
|
1077
|
+
test: /\.css$/i,
|
|
1078
|
+
use: [
|
|
1079
|
+
'style-loader',
|
|
1080
|
+
{
|
|
1081
|
+
loader: 'css-loader',
|
|
1082
|
+
options: {
|
|
1083
|
+
importLoaders: 2,
|
|
1084
|
+
// 0 => no loaders (default);
|
|
1085
|
+
// 1 => postcss-loader;
|
|
1086
|
+
// 2 => postcss-loader, sass-loader
|
|
1087
|
+
},
|
|
1088
|
+
},
|
|
1089
|
+
'postcss-loader',
|
|
1090
|
+
'sass-loader',
|
|
1091
|
+
],
|
|
1092
|
+
},
|
|
1093
|
+
],
|
|
1094
|
+
},
|
|
1095
|
+
};
|
|
1096
|
+
```
|
|
1097
|
+
|
|
1098
|
+
This may change in the future when the module system (i. e. webpack) supports loader matching by origin.
|
|
1099
|
+
|
|
1012
1100
|
### `esModule`
|
|
1013
1101
|
|
|
1014
1102
|
Type: `Boolean`
|
|
1015
|
-
Default: `
|
|
1103
|
+
Default: `true`
|
|
1016
1104
|
|
|
1017
|
-
By default, `css-loader` generates JS modules that use the
|
|
1105
|
+
By default, `css-loader` generates JS modules that use the ES modules syntax.
|
|
1018
1106
|
There are some cases in which using ES modules is beneficial, like in the case of [module concatenation](https://webpack.js.org/plugins/module-concatenation-plugin/) and [tree shaking](https://webpack.js.org/guides/tree-shaking/).
|
|
1019
1107
|
|
|
1020
|
-
You can enable a
|
|
1108
|
+
You can enable a CommonJS modules syntax using:
|
|
1021
1109
|
|
|
1022
1110
|
**webpack.config.js**
|
|
1023
1111
|
|
|
@@ -1029,7 +1117,7 @@ module.exports = {
|
|
|
1029
1117
|
test: /\.css$/i,
|
|
1030
1118
|
loader: 'css-loader',
|
|
1031
1119
|
options: {
|
|
1032
|
-
esModule:
|
|
1120
|
+
esModule: false,
|
|
1033
1121
|
},
|
|
1034
1122
|
},
|
|
1035
1123
|
],
|
|
@@ -1084,7 +1172,6 @@ module.exports = {
|
|
|
1084
1172
|
module: {
|
|
1085
1173
|
rules: [
|
|
1086
1174
|
{
|
|
1087
|
-
// For CSS modules
|
|
1088
1175
|
// For pure CSS - /\.css$/i,
|
|
1089
1176
|
// For Sass/SCSS - /\.((c|sa|sc)ss)$/i,
|
|
1090
1177
|
// For Less - /\.((c|le)ss)$/i,
|
|
@@ -1106,9 +1193,7 @@ module.exports = {
|
|
|
1106
1193
|
options: { plugins: () => [postcssPresetEnv({ stage: 0 })] },
|
|
1107
1194
|
},
|
|
1108
1195
|
// Can be `less-loader`
|
|
1109
|
-
// The `test` property should be `\.less/i`
|
|
1110
1196
|
{
|
|
1111
|
-
test: /\.s[ac]ss$/i,
|
|
1112
1197
|
loader: 'sass-loader',
|
|
1113
1198
|
},
|
|
1114
1199
|
],
|
|
@@ -1125,6 +1210,39 @@ module.exports = {
|
|
|
1125
1210
|
};
|
|
1126
1211
|
```
|
|
1127
1212
|
|
|
1213
|
+
### Resolve unresolved URLs using an alias
|
|
1214
|
+
|
|
1215
|
+
**index.css**
|
|
1216
|
+
|
|
1217
|
+
```css
|
|
1218
|
+
.class {
|
|
1219
|
+
background: url(/assets/unresolved/img.png);
|
|
1220
|
+
}
|
|
1221
|
+
```
|
|
1222
|
+
|
|
1223
|
+
**webpack.config.js**
|
|
1224
|
+
|
|
1225
|
+
```js
|
|
1226
|
+
module.exports = {
|
|
1227
|
+
module: {
|
|
1228
|
+
rules: [
|
|
1229
|
+
{
|
|
1230
|
+
test: /\.css$/i,
|
|
1231
|
+
use: ['style-loader', 'css-loader'],
|
|
1232
|
+
},
|
|
1233
|
+
],
|
|
1234
|
+
},
|
|
1235
|
+
resolve: {
|
|
1236
|
+
alias: {
|
|
1237
|
+
'/assets/unresolved/img.png': path.resolve(
|
|
1238
|
+
__dirname,
|
|
1239
|
+
'assets/real-path-to-img/img.png'
|
|
1240
|
+
),
|
|
1241
|
+
},
|
|
1242
|
+
},
|
|
1243
|
+
};
|
|
1244
|
+
```
|
|
1245
|
+
|
|
1128
1246
|
## Contributing
|
|
1129
1247
|
|
|
1130
1248
|
Please take a moment to read our contributing guidelines if you haven't yet done so.
|