Skip to content

Commit c5b6da4

Browse files
committed
Fix docs structure
1 parent 3305c74 commit c5b6da4

File tree

1 file changed

+84
-42
lines changed

1 file changed

+84
-42
lines changed

README.md

Lines changed: 84 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,49 @@ module.exports = {
114114
}
115115
```
116116

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
118160

119161
When using [postcss-import] plugin, you may want to tell webpack about
120162
dependencies coming from your `@import` directives.
@@ -147,7 +189,7 @@ module.exports = {
147189
[webpack loader-context]: http://webpack.github.io/docs/loaders.html#loader-context
148190
[postcss-import]: https://github.com/postcss/postcss-import
149191

150-
## Integration with CSS Modules
192+
### With CSS Modules
151193

152194
`postcss-loader` [cannot be used] with [CSS Modules] out of the box due
153195
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`.
166208
[postcss-modules]: https://github.com/outpunk/postcss-modules
167209
[cannot be used]: https://github.com/webpack/css-loader/issues/137
168210
[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-
209211
## Custom Syntaxes
210212

211213
PostCSS can transforms styles in any syntax, not only in CSS.
@@ -245,3 +247,43 @@ module.exports = {
245247
}
246248
}
247249
```
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

Comments
 (0)