You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-5Lines changed: 30 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ module.exports = {
65
65
};
66
66
```
67
67
68
-
Run `webpack` using your preferred method.
68
+
Finally, run `webpack` using the method you normally use (e.g., via CLI or an npm script).
69
69
70
70
If you need to extract CSS into a separate file (i.e. do not store CSS in a JS module), consider using the [recommend example](https://github.com/webpack-contrib/css-loader#recommend).
71
71
@@ -143,7 +143,9 @@ module.exports = {
143
143
144
144
#### `object`
145
145
146
-
Allows filtering of `url()` values. Any filtered `url()` will not be resolved (left in the code as they were written).
146
+
Allows filtering of `url()` values.
147
+
148
+
Any filtered `url()` will not be resolved (left in the code as they were written).
147
149
148
150
**webpack.config.js**
149
151
@@ -202,7 +204,9 @@ type importFn =
202
204
Default: `true`
203
205
204
206
Allows you to enable or disable handling of `@import` at-rules.
207
+
205
208
Controls how `@import` statements are resolved.
209
+
206
210
Absolute URLs in `@import` will be moved in runtime code.
Allows filtering of `@import`. Any filtered `@import` will not be resolved (left in the code as they were written).
266
+
Allows filtering of `@import`.
267
+
268
+
Any filtered `@import` will not be resolved (left in the code as they were written).
263
269
264
270
**webpack.config.js**
265
271
@@ -928,6 +934,7 @@ type localIdentHashSalt = string;
928
934
Default: `undefined`
929
935
930
936
Allows to add custom hash to generate more unique classes.
937
+
931
938
For more information see [output.hashSalt](https://webpack.js.org/configuration/output/#outputhashsalt).
932
939
933
940
**webpack.config.js**
@@ -961,6 +968,7 @@ type localIdentHashFunction = string;
961
968
Default: `md4`
962
969
963
970
Allows to specify hash function to generate classes .
971
+
964
972
For more information see [output.hashFunction](https://webpack.js.org/configuration/output/#outputhashfunction).
965
973
966
974
**webpack.config.js**
@@ -994,6 +1002,7 @@ type localIdentHashDigest = string;
994
1002
Default: `hex`
995
1003
996
1004
Allows to specify hash digest to generate classes.
1005
+
997
1006
For more information see [output.hashDigest](https://webpack.js.org/configuration/output/#outputhashdigest).
998
1007
999
1008
**webpack.config.js**
@@ -1027,6 +1036,7 @@ type localIdentHashDigestLength = number;
1027
1036
Default: `20`
1028
1037
1029
1038
Allows to specify hash digest length to generate classes.
1039
+
1030
1040
For more information, see [output.hashDigestLength](https://webpack.js.org/configuration/output/#outputhashdigestlength).
1031
1041
1032
1042
**webpack.config.js**
@@ -1124,7 +1134,9 @@ type getLocalIdent = (
1124
1134
Default: `undefined`
1125
1135
1126
1136
Allows to specify a function to generate the classname.
1137
+
1127
1138
By default we use built-in function to generate a classname.
1139
+
1128
1140
If your custom function returns `null` or `undefined`, the built-in generator is used as a `fallback`.
1129
1141
1130
1142
**webpack.config.js**
@@ -1218,6 +1230,7 @@ module.exports = {
1218
1230
```
1219
1231
1220
1232
To set a custom name for namedExport, can use [`exportLocalsConvention`](#exportLocalsConvention) option as a function.
1233
+
1221
1234
See below in the [`examples`](#examples) section.
1222
1235
1223
1236
##### `exportGlobals`
@@ -1388,7 +1401,9 @@ Default: `false`
1388
1401
Export only locals.
1389
1402
1390
1403
**Useful** when you use **css modules** for pre-rendering (for example SSR).
1404
+
1391
1405
For pre-rendering with `mini-css-extract-plugin` you should use this option instead of `style-loader!css-loader`**in the pre-rendering bundle**.
1406
+
1392
1407
It doesn't embed CSS; it only exports the identifier mappings.
1393
1408
1394
1409
**webpack.config.js**
@@ -1431,7 +1446,9 @@ type getJSON = ({
1431
1446
1432
1447
Default: `undefined`
1433
1448
1434
-
Enables a callback to output the CSS modules mapping JSON. The callback is invoked with an object containing the following:
1449
+
Enables a callback to output the CSS modules mapping JSON.
1450
+
1451
+
The callback is invoked with an object containing the following:
1435
1452
1436
1453
-`resourcePath`: the absolute path of the original resource, e.g., `/foo/bar/baz.module.css`
1437
1454
@@ -1473,6 +1490,7 @@ Enables a callback to output the CSS modules mapping JSON. The callback is invok
1473
1490
```
1474
1491
1475
1492
Using `getJSON`, it's possible to output a file with all CSS module mappings.
1493
+
1476
1494
In the following example, we use `getJSON` to cache canonical mappings and add stand-ins for any composed values (through `composes`), and we use a custom plugin to consolidate the values and output them to a file:
1477
1495
1478
1496
**webpack.config.js**
@@ -1740,6 +1758,7 @@ type esModule = boolean;
1740
1758
Default: `true`
1741
1759
1742
1760
By default, `css-loader` generates JS modules that use the ES modules syntax.
1761
+
1743
1762
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/).
Allows exporting styles as array with modules, string or [constructable stylesheet](https://developers.google.com/web/updates/2019/02/constructable-stylesheets) (i.e. [`CSSStyleSheet`](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet)).
1795
+
1776
1796
The default value is `'array'`, i.e. loader exports an array of modules with a specific API which is used in `style-loader` or other.
1777
1797
1778
1798
**webpack.config.js**
@@ -1983,7 +2003,9 @@ module.exports = {
1983
2003
### Recommend
1984
2004
1985
2005
For `production` builds, it's recommended to extract the CSS from your bundle being able to use parallel loading of CSS/JS resources later on.
2006
+
1986
2007
This can be achieved by using the [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin), because it creates separate css files.
2008
+
1987
2009
For `development` mode (including `webpack-dev-server`) you can use [style-loader](https://github.com/webpack-contrib/style-loader), because it injects CSS into the DOM using multiple `<style></style>` and works faster.
1988
2010
1989
2011
> [!NOTE]
@@ -2212,6 +2234,7 @@ module.exports = {
2212
2234
### Separating `Interoperable CSS`-only and `CSS Module` features
2213
2235
2214
2236
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 the `mode` option for all files that do not match the `*.module.scss` naming convention. This is for reference, as having `ICSS` features applied to all files was default `css-loader` behavior before v4.
2237
+
2215
2238
Meanwhile, all files matching `*.module.scss` are treated as `CSS Modules` in this example.
2216
2239
2217
2240
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).
0 commit comments