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
+32-21
Original file line number
Diff line number
Diff line change
@@ -565,7 +565,6 @@ module.exports = {
565
565
loader:'css-loader',
566
566
options: {
567
567
modules: {
568
-
// All files for which /\.module\.\w+$/i.test(filename) return true
569
568
auto:true,
570
569
},
571
570
},
@@ -577,7 +576,7 @@ module.exports = {
577
576
578
577
###### `RegExp`
579
578
580
-
Enable css modules for files based on filename and satisfying `/youRegExp/.test(filename)` regex.
579
+
Enable css modules for files based on a filename and satisfying your regex.
581
580
582
581
**webpack.config.js**
583
582
@@ -590,8 +589,7 @@ module.exports = {
590
589
loader:'css-loader',
591
590
options: {
592
591
modules: {
593
-
// All files for which /youRegExp/i.test(filename) return true
594
-
auto:/youRegExp/i,
592
+
auto:/\.custom-module\.\w+$/i,
595
593
},
596
594
},
597
595
},
@@ -609,9 +607,7 @@ Setup `mode` option. You can omit the value when you want `local` mode.
609
607
610
608
###### `String`
611
609
612
-
Possible values:
613
-
614
-
`local`, `global`, `pure`
610
+
Possible values - `local`, `global`, and `pure`.
615
611
616
612
**webpack.config.js**
617
613
@@ -637,7 +633,7 @@ module.exports = {
637
633
638
634
Allows set different values for the `mode` option based on a filename
639
635
640
-
Possible return values - `local`, `global` and `pure`
636
+
Possible return values - `local`, `global`, and `pure`.
641
637
642
638
**webpack.config.js**
643
639
@@ -650,9 +646,13 @@ module.exports = {
650
646
loader:'css-loader',
651
647
options: {
652
648
modules: {
653
-
// Callback must return "local", "global" or "pure"
654
-
mode: (filename) => {
655
-
if (/global.css$/i.test(filename)) {
649
+
// Callback must return "local", "global", or "pure" values
650
+
mode: (resourcePath) => {
651
+
if (/pure.css$/i.test(resourcePath)) {
652
+
return'pure';
653
+
}
654
+
655
+
if (/global.css$/i.test(resourcePath)) {
656
656
return'global';
657
657
}
658
658
@@ -1049,33 +1049,44 @@ For production builds it's recommended to extract the CSS from your bundle being
1049
1049
1050
1050
- As an alternative, if seeking better development performance and css outputs that mimic production. [extract-css-chunks-webpack-plugin](https://github.com/faceyspacey/extract-css-chunks-webpack-plugin) offers a hot module reload friendly, extended version of mini-css-extract-plugin. HMR real CSS files in dev, works like mini-css in non-dev
1051
1051
1052
-
### CSSmodules and pure CSS
1052
+
### Pure CSS, CSS modules and PostCSS
1053
1053
1054
-
When you have pure CSS (without CSS modules) and CSS modules in project you can use this setup:
1054
+
When you have pure CSS (without CSS modules), CSS modules and PostCSS in your project you can use this setup:
1055
1055
1056
1056
**webpack.config.js**
1057
1057
1058
1058
```js
1059
1059
module.exports= {
1060
1060
module: {
1061
1061
rules: [
1062
-
{
1063
-
// For pure CSS (without CSS modules)
1064
-
test:/\.css$/i,
1065
-
exclude:/\.module\.css$/i,
1066
-
use: ['style-loader', 'css-loader'],
1067
-
},
1068
1062
{
1069
1063
// For CSS modules
1070
-
test:/\.module\.css$/i,
1064
+
// For pure CSS - /\.css$/i,
1065
+
// For Sass/SCSS - /\.((c|sa|sc)ss)$/i,
1066
+
// For Less - /\.((c|le)ss)$/i,
1067
+
test:/\.((c|sa|sc)ss)$/i,
1071
1068
use: [
1072
1069
'style-loader',
1073
1070
{
1074
1071
loader:'css-loader',
1075
1072
options: {
1076
-
modules:true,
1073
+
// Run `postcss-loader` on each CSS `@import`, do not forget that `sass-loader` compile non CSS `@import`'s into a single file
1074
+
// If you need run `sass-loader` and `postcss-loader` on each CSS `@import` please set it to `2`
1075
+
importLoaders:1,
1076
+
// Automatically enable css modules for files satisfying `/\.module\.\w+$/i` RegExp.
0 commit comments