@@ -38,7 +38,11 @@ npm i -D postcss-loader
38
38
``` js
39
39
module .exports = {
40
40
parser: ' sugarss' ,
41
- plugins: [[' postcss-import' , {}], [' postcss-preset-env' ], ' postcss-short' ],
41
+ plugins: {
42
+ ' postcss-import' : {},
43
+ ' postcss-preset-env' : {},
44
+ cssnano: {},
45
+ },
42
46
};
43
47
```
44
48
@@ -109,15 +113,12 @@ module.exports = {
109
113
110
114
<h2 align =" center " >Options</h2 >
111
115
112
- | Name | Type | Default | Description |
113
- | :------------------------: | :----------------------------------------------------------: | :----------------: | :------------------------------------------- |
114
- | [ ` exec ` ] ( #exec ) | ` {Boolean} ` | ` undefined ` | Enable PostCSS Parser support in ` CSS-in-JS ` |
115
- | [ ` parser ` ] ( #syntaxes ) | ` {String\|Object\|Function} ` | ` undefined ` | Set PostCSS Parser |
116
- | [ ` syntax ` ] ( #syntaxes ) | ` {String\|Object} ` | ` undefined ` | Set PostCSS Syntax |
117
- | [ ` stringifier ` ] ( #syntaxes ) | ` {String\|Object\|Function} ` | ` undefined ` | Set PostCSS Stringifier |
118
- | [ ` config ` ] ( #config ) | ` {String\|Object\|Boolean} ` | ` undefined ` | Set ` postcss.config.js ` config path && ` ctx ` |
119
- | [ ` plugins ` ] ( #plugins ) | ` {Function\|Object\|Array<String\|Function\|Object\|Array>} ` | ` [] ` | Set PostCSS Plugins |
120
- | [ ` sourceMap ` ] ( #sourcemap ) | ` {String\|Boolean} ` | ` compiler.devtool ` | Enables/Disables generation of source maps |
116
+ | Name | Type | Default | Description |
117
+ | :---------------------------------: | :-------------------------: | :-----------------------------------: | :---------------------------------------------- |
118
+ | [ ` exec ` ] ( #exec ) | ` {Boolean} ` | ` undefined ` | Enable PostCSS Parser support in ` CSS-in-JS ` |
119
+ | [ ` config ` ] ( #config ) | ` {String\|Object\|Boolean} ` | ` undefined ` | Set ` postcss.config.js ` config path && ` ctx ` |
120
+ | [ ` postcssOptions ` ] ( #postcssOptions ) | ` {Object} ` | ` defaults values for Postcss.process ` | Set Postcss.process options and postcss plugins |
121
+ | [ ` sourceMap ` ] ( #sourcemap ) | ` {String\|Boolean} ` | ` compiler.devtool ` | Enables/Disables generation of source maps |
121
122
122
123
### ` Exec `
123
124
@@ -139,7 +140,12 @@ module.exports = {
139
140
{ loader: ' css-loader' , options: { importLoaders: 1 } },
140
141
{
141
142
loader: ' postcss-loader' ,
142
- options: { parser: ' sugarss' , exec: true },
143
+ options: {
144
+ postcssOptions: {
145
+ parser: ' sugarss' ,
146
+ },
147
+ exec: true ,
148
+ },
143
149
},
144
150
],
145
151
},
@@ -290,7 +296,16 @@ module.exports = {
290
296
};
291
297
```
292
298
293
- ### ` Plugins `
299
+ ### ` postcssOptions `
300
+
301
+ | Name | Type | Default | Description |
302
+ | :---------------------------: | :-------------------------------------------: | :---------: | :----------------------------- |
303
+ | [ ` plugins ` ] ( #plugins ) | ` {Function\|Object\|Array<Function\|Object>} ` | ` [] ` | Set PostCSS Plugins |
304
+ | [ ` parser ` ] ( #parser ) | ` {String\|Object\|Function} ` | ` undefined ` | Set custom PostCSS Parser |
305
+ | [ ` syntax ` ] ( #syntax ) | ` {String\|Object} ` | ` undefined ` | Set custom PostCSS Syntax |
306
+ | [ ` stringifier ` ] ( #stringifier ) | ` {String\|Object\|Function} ` | ` undefined ` | Set custom PostCSS Stringifier |
307
+
308
+ #### ` Plugins `
294
309
295
310
Type: ` Function|Object|Array<String|Function\|Object|Array> `
296
311
Default: ` [] `
@@ -352,11 +367,13 @@ module.exports = {
352
367
test: / \. css$ / i ,
353
368
loader: ' postcss-loader' ,
354
369
options: {
355
- plugins : (loader ) => [
356
- require (' postcss-import' )({ root: loader .resourcePath }),
357
- require (' postcss-preset-env' )(),
358
- require (' cssnano' )(),
359
- ],
370
+ postcssOptions: {
371
+ plugins : (loader ) => [
372
+ require (' postcss-import' )({ root: loader .resourcePath }),
373
+ require (' postcss-preset-env' )(),
374
+ require (' cssnano' )(),
375
+ ],
376
+ },
360
377
},
361
378
},
362
379
],
@@ -394,11 +411,11 @@ It is possible to disable the plugin specified in the config.
394
411
395
412
``` js
396
413
module .exports = {
397
- plugins: [
398
- [ ' postcss-short' , { prefix: ' x' }] ,
399
- ' postcss-import' ,
400
- ' postcss-nested' ,
401
- ] ,
414
+ plugins: {
415
+ ' postcss-short' : { prefix: ' x' },
416
+ ' postcss-import' : {} ,
417
+ ' postcss-nested' : {} ,
418
+ } ,
402
419
};
403
420
```
404
421
@@ -412,11 +429,13 @@ module.exports = {
412
429
test: / \. css$ / i ,
413
430
loader: ' postcss-loader' ,
414
431
options: {
415
- plugins: {
416
- ' postcss-import' : {},
417
- ' postcss-nested' : {},
418
- // Turn off the plugin
419
- ' postcss-short' : false ,
432
+ postcssOptions: {
433
+ plugins: {
434
+ ' postcss-import' : {},
435
+ ' postcss-nested' : {},
436
+ // Turn off the plugin
437
+ ' postcss-short' : false ,
438
+ },
420
439
},
421
440
},
422
441
},
@@ -425,17 +444,6 @@ module.exports = {
425
444
};
426
445
```
427
446
428
- ### ` Syntaxes `
429
-
430
- Type: ` String|Object `
431
- Default: ` undefined `
432
-
433
- | Name | Type | Default | Description |
434
- | :---------------------------: | :--------------------------: | :---------: | :------------------------- |
435
- | [ ` parser ` ] ( #parser ) | ` {String\|Object} ` | ` undefined ` | Custom PostCSS Parser |
436
- | [ ` syntax ` ] ( #syntax ) | ` {String\|Object} ` | ` undefined ` | Custom PostCSS Syntax |
437
- | [ ` stringifier ` ] ( #stringifier ) | ` {String\|Object\|Function} ` | ` undefined ` | Custom PostCSS Stringifier |
438
-
439
447
#### ` Parser `
440
448
441
449
Type: ` String|Object|Function `
@@ -455,8 +463,10 @@ module.exports = {
455
463
test: / \. sss$ / i ,
456
464
loader: ' postcss-loader' ,
457
465
options: {
458
- // Will be converted to `require('sugarss')`
459
- parser: ' sugarss' ,
466
+ postcssOptions: {
467
+ // Will be converted to `require('sugarss')`
468
+ parser: ' sugarss' ,
469
+ },
460
470
},
461
471
},
462
472
],
@@ -476,7 +486,9 @@ module.exports = {
476
486
test: / \. sss$ / i ,
477
487
loader: ' postcss-loader' ,
478
488
options: {
479
- parser: require (' sugarss' ),
489
+ postcssOptions: {
490
+ parser: require (' sugarss' ),
491
+ },
480
492
},
481
493
},
482
494
],
@@ -496,7 +508,9 @@ module.exports = {
496
508
test: / \. sss$ / i ,
497
509
loader: ' postcss-loader' ,
498
510
options: {
499
- parser: require (' sugarss' ).parse ,
511
+ postcssOptions: {
512
+ parser: require (' sugarss' ).parse ,
513
+ },
500
514
},
501
515
},
502
516
],
@@ -523,8 +537,10 @@ module.exports = {
523
537
test: / \. css$ / i ,
524
538
loader: ' postcss-loader' ,
525
539
options: {
526
- // Will be converted to `require('sugarss')`
527
- syntax: ' sugarss' ,
540
+ postcssOptions: {
541
+ // Will be converted to `require('sugarss')`
542
+ syntax: ' sugarss' ,
543
+ },
528
544
},
529
545
},
530
546
],
@@ -544,7 +560,9 @@ module.exports = {
544
560
test: / \. css$ / i ,
545
561
loader: ' postcss-loader' ,
546
562
options: {
547
- stringifier: require (' sugarss' ),
563
+ postcssOptions: {
564
+ stringifier: require (' sugarss' ),
565
+ },
548
566
},
549
567
},
550
568
],
@@ -571,8 +589,10 @@ module.exports = {
571
589
test: / \. css$ / i ,
572
590
loader: ' postcss-loader' ,
573
591
options: {
574
- // Will be converted to `require('sugarss')`
575
- stringifier: ' sugarss' ,
592
+ postcssOptions: {
593
+ // Will be converted to `require('sugarss')`
594
+ stringifier: ' sugarss' ,
595
+ },
576
596
},
577
597
},
578
598
],
@@ -592,7 +612,9 @@ module.exports = {
592
612
test: / \. css$ / i ,
593
613
loader: ' postcss-loader' ,
594
614
options: {
595
- stringifier: require (' sugarss' ),
615
+ postcssOptions: {
616
+ stringifier: require (' sugarss' ),
617
+ },
596
618
},
597
619
},
598
620
],
@@ -615,7 +637,9 @@ module.exports = {
615
637
test: / \. css$ / i ,
616
638
loader: ' postcss-loader' ,
617
639
options: {
618
- stringifier: midas .stringifier ,
640
+ postcssOptions: {
641
+ stringifier: midas .stringifier ,
642
+ },
619
643
},
620
644
},
621
645
],
@@ -707,7 +731,9 @@ module.exports = {
707
731
{
708
732
loader: ' postcss-loader' ,
709
733
options: {
710
- plugins: [' postcss-import' , ' stylelint' ],
734
+ postcssOptions: {
735
+ plugins: [' postcss-import' , ' stylelint' ],
736
+ },
711
737
},
712
738
},
713
739
],
@@ -733,7 +759,9 @@ module.exports = {
733
759
{
734
760
loader: ' postcss-loader' ,
735
761
options: {
736
- plugins: [[' autoprefixer' , { ... options }]],
762
+ postcssOptions: {
763
+ plugins: [[' autoprefixer' , { ... options }]],
764
+ },
737
765
},
738
766
},
739
767
],
@@ -797,7 +825,14 @@ module.exports = {
797
825
use: [
798
826
' style-loader' ,
799
827
{ loader: ' css-loader' , options: { importLoaders: 2 } },
800
- { loader: ' postcss-loader' , options: { parser: ' postcss-js' } },
828
+ {
829
+ loader: ' postcss-loader' ,
830
+ options: {
831
+ postcssOptions: {
832
+ parser: ' postcss-js' ,
833
+ },
834
+ },
835
+ },
801
836
' babel-loader' ,
802
837
],
803
838
},
@@ -896,7 +931,9 @@ module.exports = {
896
931
{
897
932
loader: ' postcss-loader' ,
898
933
options: {
899
- plugins: [postcssPlugin ()],
934
+ postcssOptions: {
935
+ plugins: [postcssPlugin ()],
936
+ },
900
937
},
901
938
},
902
939
],
@@ -942,7 +979,9 @@ module.exports = {
942
979
{
943
980
loader: ' postcss-loader' ,
944
981
options: {
945
- plugins: [postcssPlugin ()],
982
+ postcssOptions: {
983
+ plugins: [postcssPlugin ()],
984
+ },
946
985
},
947
986
},
948
987
],
@@ -982,7 +1021,9 @@ module.exports = {
982
1021
983
1022
``` js
984
1023
module .exports = (loaderContext ) => ({
985
- plugins: [require (' path/to/customPlugin' )(loaderContext)],
1024
+ postcssOptions: {
1025
+ plugins: [require (' path/to/customPlugin' )(loaderContext)],
1026
+ },
986
1027
});
987
1028
```
988
1029
0 commit comments