File tree Expand file tree Collapse file tree 3 files changed +46
-3
lines changed
Expand file tree Collapse file tree 3 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,43 @@ module.exports = {
7070}
7171```
7272
73+ ## Plugins Function
74+
75+ If you need to link any of the postcss plugins to the webpack context, you can
76+ define a function that returns your plugins. The function is executed with the
77+ same context provided to postcss-loader, allowing access to webpack loader API
78+
79+ ``` js
80+ var cssimport = require (' postcss-import' );
81+ var autoprefixer = require (' autoprefixer-core' );
82+
83+ module .exports = {
84+ module: {
85+ loaders: [
86+ {
87+ test: / \. css$ / ,
88+ loader: " style-loader!css-loader!postcss-loader"
89+ }
90+ ]
91+ },
92+ postcss : function () {
93+ // The context of this function is the same provided to postcss-loader
94+ // see: http://webpack.github.io/docs/loaders.html
95+
96+ return [
97+ cssimport ({
98+ // see postcss-import docs to learn about onImport param
99+ // https://github.com/postcss/postcss-import
100+
101+ onImport : function (files ) {
102+ files .forEach (this .addDependency );
103+ }.bind (this )
104+ }),
105+ autoprefixer
106+ ];
107+ }
108+ }
109+ ```
73110
74111## Safe Mode
75112
Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ module.exports = function (source, map) {
1818 if ( params . safe ) opts . safe = true ;
1919
2020 var plugins = this . options . postcss ;
21+ if ( typeof plugins === 'function' ) {
22+ plugins = plugins . call ( this ) ;
23+ }
24+
2125 if ( typeof plugins === 'undefined' ) {
2226 plugins = [ ] ;
2327 } else if ( params . pack ) {
Original file line number Diff line number Diff line change @@ -11,8 +11,10 @@ module.exports = {
1111 path : path . join ( __dirname , '..' , 'build' ) ,
1212 filename : 'test.js'
1313 } ,
14- postcss : {
15- defaults : [ blue , red ] ,
16- blues : [ blue ]
14+ postcss : function ( ) {
15+ return {
16+ defaults : [ blue , red ] ,
17+ blues : [ blue ]
18+ } ;
1719 }
1820} ;
You can’t perform that action at this time.
0 commit comments