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 = {
123123[ webpack loader-context ] : http://webpack.github.io/docs/loaders.html#loader-context
124124[ postcss-import ] : https://github.com/postcss/postcss-import
125125
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+
126155## Custom Syntaxes
127156
128157PostCSS 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) {
3939 var loader = this ;
4040 var callback = this . async ( ) ;
4141
42+ if ( params . parser === 'postcss-js' ) {
43+ source = this . exec ( source , this . resource ) ;
44+ }
45+
4246 postcss ( plugins )
4347 . process ( source , opts ) . then ( function ( result ) {
4448 result . warnings ( ) . forEach ( function ( msg ) {
Original file line number Diff line number Diff line change 1515 },
1616 "devDependencies" : {
1717 "postcss-safe-parser" : " 1.0.1" ,
18+ "postcss-js" : " 0.1.0" ,
1819 "webpack-stream" : " 2.1.1" ,
1920 "gulp-eslint" : " 1.0.0" ,
2021 "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 () {
2323 expect ( css ) . to . eql ( 'a { one color: red }\n' ) ;
2424 } ) ;
2525
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+
2633} ) ;
You can’t perform that action at this time.
0 commit comments