@@ -114,7 +114,49 @@ module.exports = {
114
114
}
115
115
```
116
116
117
- ## Integration with postcss-import
117
+ ## Custom Syntaxes
118
+
119
+ PostCSS can transforms styles in any syntax, not only in CSS.
120
+ There are 3 parameters to control syntax:
121
+
122
+ * ` syntax ` accepts module name with ` parse ` and ` stringify ` function.
123
+ * ` parser ` accepts module name with input parser function.
124
+ * ` stringifier ` accepts module name with output stringifier function.
125
+
126
+ For example, you can use [ Safe Parser] to find and fix any CSS errors:
127
+
128
+ ``` js
129
+ var css = require (' postcss?parser=postcss-safe-parser!./broken' )
130
+ ```
131
+
132
+ [ Safe Parser ] : https://github.com/postcss/postcss-safe-parser
133
+
134
+ If you need to pass the function directly instead of a module name,
135
+ you can do so through the webpack postcss option, as such:
136
+
137
+ ``` js
138
+ var sugarss = require (' sugarss' )
139
+ module .exports = {
140
+ module: {
141
+ loaders: [
142
+ {
143
+ test: / \. css$ / ,
144
+ loader: " style-loader!css-loader!postcss-loader"
145
+ }
146
+ ]
147
+ },
148
+ postcss : function () {
149
+ return {
150
+ plugins: [autoprefixer, precss],
151
+ syntax: sugarss
152
+ };
153
+ }
154
+ }
155
+ ```
156
+
157
+ ## Examples
158
+
159
+ ### With postcss-import
118
160
119
161
When using [ postcss-import] plugin, you may want to tell webpack about
120
162
dependencies coming from your ` @import ` directives.
@@ -147,7 +189,7 @@ module.exports = {
147
189
[ webpack loader-context ] : http://webpack.github.io/docs/loaders.html#loader-context
148
190
[ postcss-import ] : https://github.com/postcss/postcss-import
149
191
150
- ## Integration with CSS Modules
192
+ ### With CSS Modules
151
193
152
194
` postcss-loader ` [ cannot be used] with [ CSS Modules] out of the box due
153
195
to the way ` css-loader ` processes file imports. To make them work properly,
@@ -166,46 +208,6 @@ or use [postcss-modules] plugin instead of `css-loader`.
166
208
[ postcss-modules ] : https://github.com/outpunk/postcss-modules
167
209
[ cannot be used ] : https://github.com/webpack/css-loader/issues/137
168
210
[ CSS Modules ] : https://github.com/webpack/css-loader#css-modules
169
-
170
- ## JS Styles
171
-
172
- If you want to process styles written in JavaScript
173
- you can use the [ postcss-js] parser.
174
-
175
- ``` js
176
- {
177
- test: / \. style. js$ / ,
178
- loader: " style-loader!css-loader!postcss-loader?parser=postcss-js"
179
- }
180
- ```
181
-
182
- Or use can use even ES6 in JS styles by Babel:
183
-
184
- ``` js
185
- {
186
- test: / \. style. js$ / ,
187
- loader: " style-loader!css-loader!postcss-loader?parser=postcss-js!babel"
188
- }
189
- ```
190
-
191
- As result you will be able to write styles as:
192
-
193
- ``` js
194
- import colors from ' ../config/colors' ;
195
-
196
- export default {
197
- ' .menu' : {
198
- color: colors .main ,
199
- height: 25 ,
200
- ' &_link' : {
201
- color: ' white'
202
- }
203
- }
204
- }
205
- ```
206
-
207
- [ postcss-js ] : https://github.com/postcss/postcss-js
208
-
209
211
## Custom Syntaxes
210
212
211
213
PostCSS can transforms styles in any syntax, not only in CSS.
@@ -245,3 +247,43 @@ module.exports = {
245
247
}
246
248
}
247
249
```
250
+
251
+
252
+ ### JS Styles
253
+
254
+ If you want to process styles written in JavaScript
255
+ you can use the [ postcss-js] parser.
256
+
257
+ ``` js
258
+ {
259
+ test: / \. style. js$ / ,
260
+ loader: " style-loader!css-loader!postcss-loader?parser=postcss-js"
261
+ }
262
+ ```
263
+
264
+ Or use can use even ES6 in JS styles by Babel:
265
+
266
+ ``` js
267
+ {
268
+ test: / \. style. js$ / ,
269
+ loader: " style-loader!css-loader!postcss-loader?parser=postcss-js!babel"
270
+ }
271
+ ```
272
+
273
+ As result you will be able to write styles as:
274
+
275
+ ``` js
276
+ import colors from ' ../config/colors' ;
277
+
278
+ export default {
279
+ ' .menu' : {
280
+ color: colors .main ,
281
+ height: 25 ,
282
+ ' &_link' : {
283
+ color: ' white'
284
+ }
285
+ }
286
+ }
287
+ ```
288
+
289
+ [ postcss-js ] : https://github.com/postcss/postcss-js
0 commit comments