@@ -109,16 +109,19 @@ module.exports = {
109
109
110
110
## Options
111
111
112
- | Name | Type | Default | Description |
113
- | :-----------------------------------------: | :-------------------: | :-------------: | :------------------------------------------ |
114
- | ** [ ` url ` ] ( #url ) ** | ` {Boolean\|Function} ` | ` true ` | Enable/Disable ` url() ` handling |
115
- | ** [ ` import ` ] ( #import ) ** | ` {Boolean\/Function} ` | ` true ` | Enable/Disable @import handling |
116
- | ** [ ` modules ` ] ( #modules ) ** | ` {Boolean\|String} ` | ` false ` | Enable/Disable CSS Modules and setup mode |
117
- | ** [ ` localIdentName ` ] ( #localidentname ) ** | ` {String} ` | ` [hash:base64] ` | Configure the generated ident |
118
- | ** [ ` sourceMap ` ] ( #sourcemap ) ** | ` {Boolean} ` | ` false ` | Enable/Disable Sourcemaps |
119
- | ** [ ` camelCase ` ] ( #camelcase ) ** | ` {Boolean\|String} ` | ` false ` | Export Classnames in CamelCase |
120
- | ** [ ` importLoaders ` ] ( #importloaders ) ** | ` {Number} ` | ` 0 ` | Number of loaders applied before CSS loader |
121
- | ** [ ` exportOnlyLocals ` ] ( #exportonlylocals ) ** | ` {Boolean} ` | ` false ` | Export only locals |
112
+ | Name | Type | Default | Description |
113
+ | :-----------------------------------------: | :-------------------: | :-------------: | :----------------------------------------------------------------------- |
114
+ | ** [ ` url ` ] ( #url ) ** | ` {Boolean\|Function} ` | ` true ` | Enable/Disable ` url() ` handling |
115
+ | ** [ ` import ` ] ( #import ) ** | ` {Boolean\/Function} ` | ` true ` | Enable/Disable @import handling |
116
+ | ** [ ` modules ` ] ( #modules ) ** | ` {Boolean\|String} ` | ` false ` | Enable/Disable CSS Modules and setup mode |
117
+ | ** [ ` localIdentName ` ] ( #localidentname ) ** | ` {String} ` | ` [hash:base64] ` | Configure the generated ident |
118
+ | ** [ ` context ` ] ( #context ) ** | ` {String} ` | ` undefined ` | Allow to redefine basic loader context for local ident name |
119
+ | ** [ ` hashPrefix ` ] ( #hashprefix ) ** | ` {String} ` | ` undefined ` | Allow to add custom hash to generate more unique classes |
120
+ | ** [ ` getLocalIdent ` ] ( #getlocalident ) ** | ` {Function} ` | ` undefined ` | Configure the function to generate classname based on a different schema |
121
+ | ** [ ` sourceMap ` ] ( #sourcemap ) ** | ` {Boolean} ` | ` false ` | Enable/Disable Sourcemaps |
122
+ | ** [ ` camelCase ` ] ( #camelcase ) ** | ` {Boolean\|String} ` | ` false ` | Export Classnames in CamelCase |
123
+ | ** [ ` importLoaders ` ] ( #importloaders ) ** | ` {Number} ` | ` 0 ` | Number of loaders applied before CSS loader |
124
+ | ** [ ` exportOnlyLocals ` ] ( #exportonlylocals ) ** | ` {Boolean} ` | ` false ` | Export only locals |
122
125
123
126
### ` url `
124
127
@@ -461,7 +464,66 @@ module.exports = {
461
464
};
462
465
```
463
466
467
+ ### ` context `
468
+
469
+ Type: ` String `
470
+ Default: ` undefined `
471
+
472
+ Allow to redefine basic loader context for local ident name.
473
+ By default we use ` rootContext ` of loader.
474
+
475
+ ** webpack.config.js**
476
+
477
+ ``` js
478
+ module .exports = {
479
+ module: {
480
+ rules: [
481
+ {
482
+ test: / \. css$ / ,
483
+ loader: ' css-loader' ,
484
+ options: {
485
+ modules: true ,
486
+ context: path .resolve (__dirname , ' context' ),
487
+ },
488
+ },
489
+ ],
490
+ },
491
+ };
492
+ ```
493
+
494
+ ### ` hashPrefix `
495
+
496
+ Type: ` String `
497
+ Default: ` undefined `
498
+
499
+ Allow to add custom hash to generate more unique classes.
500
+
501
+ ** webpack.config.js**
502
+
503
+ ``` js
504
+ module .exports = {
505
+ module: {
506
+ rules: [
507
+ {
508
+ test: / \. css$ / ,
509
+ loader: ' css-loader' ,
510
+ options: {
511
+ modules: true ,
512
+ hashPrefix: ' hash' ,
513
+ },
514
+ },
515
+ ],
516
+ },
517
+ };
518
+ ```
519
+
520
+ ### ` getLocalIdent `
521
+
522
+ Type: ` Function `
523
+ Default: ` undefined `
524
+
464
525
You can also specify the absolute path to your custom ` getLocalIdent ` function to generate classname based on a different schema.
526
+ By default we use built-in function to generate a classname.
465
527
466
528
** webpack.config.js**
467
529
@@ -474,9 +536,6 @@ module.exports = {
474
536
loader: ' css-loader' ,
475
537
options: {
476
538
modules: true ,
477
- context: path .resolve (__dirname , ' context' ), // Allow to redefine basic loader context for `local-ident-name`
478
- hashPrefix: ' hash' , // Allow to add custom hash to generate more unique classes
479
- localIdentName: ' [path][name]__[local]--[hash:base64:5]' ,
480
539
getLocalIdent : (context , localIdentName , localName , options ) => {
481
540
return ' whatever_random_class_name' ;
482
541
},
@@ -654,7 +713,8 @@ module.exports = {
654
713
### Extract
655
714
656
715
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.
657
- - This can be achieved by using the [ mini-css-extract-plugin] ( https://github.com/webpack-contrib/mini-css-extract-plugin ) to extract the CSS when running in production mode.
716
+
717
+ - This can be achieved by using the [ mini-css-extract-plugin] ( https://github.com/webpack-contrib/mini-css-extract-plugin ) to extract the CSS when running in production mode.
658
718
659
719
- 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
660
720
@@ -670,21 +730,15 @@ Please take a moment to read our contributing guidelines if you haven't yet done
670
730
671
731
[ npm ] : https://img.shields.io/npm/v/css-loader.svg
672
732
[ npm-url ] : https://npmjs.com/package/css-loader
673
-
674
733
[ node ] : https://img.shields.io/node/v/css-loader.svg
675
734
[ node-url ] : https://nodejs.org
676
-
677
735
[ deps ] : https://david-dm.org/webpack-contrib/css-loader.svg
678
736
[ deps-url ] : https://david-dm.org/webpack-contrib/css-loader
679
-
680
737
[ tests ] : https://img.shields.io/circleci/project/github/webpack-contrib/css-loader.svg
681
738
[ tests-url ] : https://circleci.com/gh/webpack-contrib/css-loader
682
-
683
739
[ cover ] : https://codecov.io/gh/webpack-contrib/css-loader/branch/master/graph/badge.svg
684
740
[ cover-url ] : https://codecov.io/gh/webpack-contrib/css-loader
685
-
686
741
[ chat ] : https://badges.gitter.im/webpack/webpack.svg
687
742
[ chat-url ] : https://gitter.im/webpack/webpack
688
-
689
743
[ size ] : https://packagephobia.now.sh/badge?p=css-loader
690
744
[ size-url ] : https://packagephobia.now.sh/result?p=css-loader
0 commit comments