File tree Expand file tree Collapse file tree 5 files changed +44
-0
lines changed Expand file tree Collapse file tree 5 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,35 @@ module.exports = {
123
123
[ webpack loader-context ] : http://webpack.github.io/docs/loaders.html#loader-context
124
124
[ postcss-import ] : https://github.com/postcss/postcss-import
125
125
126
+ ## Integration with postcss-js
127
+
128
+ If you want to process styles written in Javascript you can use the [ postcss-js] parser.
129
+
130
+ ``` js
131
+ module .exports = {
132
+ module: {
133
+ loaders: [
134
+ {
135
+ test: / \. style. js$ / ,
136
+ loader: " style-loader!css-loader!postcss-loader?parser=postcss-js"
137
+ // Or using Babel
138
+ // loader: "style-loader!css-loader!postcss-loader?parser=postcss-js!babel"
139
+ }
140
+ ]
141
+ },
142
+ postcss : function (webpack ) {
143
+ return [
144
+ postcssImport ({
145
+ addDependencyTo: webpack
146
+ })
147
+ ];
148
+ }
149
+ }
150
+ ```
151
+
152
+ [ postcss-js ] : https://github.com/postcss/postcss-js
153
+
154
+
126
155
## Custom Syntaxes
127
156
128
157
PostCSS can transforms styles in any syntax, not only in CSS.
Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ module.exports = function (source, map) {
39
39
var loader = this ;
40
40
var callback = this . async ( ) ;
41
41
42
+ if ( params . parser === 'postcss-js' ) {
43
+ source = this . exec ( source , this . resource ) ;
44
+ }
45
+
42
46
postcss ( plugins )
43
47
. process ( source , opts ) . then ( function ( result ) {
44
48
result . warnings ( ) . forEach ( function ( msg ) {
Original file line number Diff line number Diff line change 15
15
},
16
16
"devDependencies" : {
17
17
"postcss-safe-parser" : " 1.0.1" ,
18
+ "postcss-js" : " 0.1.0" ,
18
19
"webpack-stream" : " 2.1.1" ,
19
20
"gulp-eslint" : " 1.0.0" ,
20
21
"gulp-mocha" : " 2.1.3" ,
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ a : { color : 'black' }
3
+ } ;
Original file line number Diff line number Diff line change @@ -23,4 +23,11 @@ describe('postcss-loader', function () {
23
23
expect ( css ) . to . eql ( 'a { one color: red }\n' ) ;
24
24
} ) ;
25
25
26
+ it ( 'processes CSS-in-JS' , function ( ) {
27
+ var css = require ( '!raw-loader!' +
28
+ '../?parser=postcss-js!' +
29
+ './cases/style.js' ) ;
30
+ expect ( css ) . to . eql ( 'a {\n color: red\n}' ) ;
31
+ } ) ;
32
+
26
33
} ) ;
You can’t perform that action at this time.
0 commit comments