Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 071c11a

Browse files
sunnylostznck
authored andcommitted
docs: add postcss document; (#139)
make `postcss`'s option consistent with `vue-loader`; fix a build warning;
1 parent cb650f3 commit 071c11a

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

config/build.js

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ rollup.rollup({
3939
'parse5',
4040
'path',
4141
'postcss',
42+
'postcss-load-config',
4243
'postcss-modules',
4344
'postcss-selector-parser',
4445
'posthtml',

docs/en/2.3/README.md

+66
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,72 @@ The output CSS will be like:
227227
}
228228
```
229229

230+
#### PostCSS
231+
232+
<p class="tip">
233+
Available in `rollup-plugin-vue@^2.5+`.
234+
</p>
235+
236+
`rollup-plugin-vue` use `PostCSS` to handle `Scoped CSS` and `CSS Module`, you can also add other `PostCSS` plugins, like [Autoprefixer](https://github.com/postcss/autoprefixer) or [cssnext](http://cssnext.io/).
237+
238+
##### Configuration
239+
240+
We use [postcss-load-config](https://github.com/michael-ciniawsky/postcss-load-config) to load config file, that means:
241+
- `postcss` field in your `package.json`
242+
- `.postcssrc` file in JSON or YAML format
243+
- `postcss.config.js` or `.postcssrc.js`
244+
245+
##### Inline Options
246+
247+
You can also use a `postcss` option, it accepts three types:
248+
- `Function`: return an array of plugins
249+
- `Array`: an array of plugins
250+
- `Object`: `postcss`'s configuration, has the most priority
251+
252+
For example, if you want to use `Autoprefixer`, that means something like
253+
254+
``` js
255+
import Autoprefixer from 'autoprefixer'
256+
257+
export default {
258+
...
259+
postcss: [Autoprefixer()],
260+
...
261+
}
262+
```
263+
264+
or
265+
266+
``` js
267+
import Autoprefixer from 'autoprefixer'
268+
269+
export default {
270+
...
271+
postcss() {
272+
return [Autoprefixer()]
273+
},
274+
...
275+
}
276+
```
277+
278+
or this:
279+
280+
``` js
281+
import Autoprefixer from 'autoprefixer'
282+
283+
export default {
284+
...
285+
postcss {
286+
plugins: [Autoprefixer()],
287+
options: {
288+
// postcss's option goes here
289+
...
290+
}
291+
},
292+
...
293+
}
294+
```
295+
230296
### Template
231297
Templates are processed into `render` function by default. You can disable this by setting:
232298
``` js

src/style/postcss.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import postcssrc from 'postcss-load-config'
22

3+
/* eslint-disable complexity */
34
export default async function (postcssOpt) {
45
let options = {}
56
let plugins = []
67

78
if (typeof postcssOpt === 'function') {
89
plugins = postcssOpt.call(this)
910
} else if (Array.isArray(postcssOpt)) {
10-
plugins = plugins.concat(postcssOpt)
11+
plugins = postcssOpt
1112
} else if (typeof postcssOpt === 'object') {
12-
options = Object.assign({}, options, postcssOpt)
13+
plugins = (typeof postcssOpt.plugins === 'function') ? postcssOpt.plugins.call(this) : postcssOpt.plugins || []
14+
options = postcssOpt.options || {}
1315
}
1416

1517
return postcssrc().then((config) => {

test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function test(name) {
3434
modules: {
3535
generateScopedName: '[name]__[local]'
3636
},
37-
postcss: [autoprefixer()],
37+
postcss: { plugins: [autoprefixer()] },
3838
compileTemplate: [
3939
'compileTemplate',
4040
'compileTemplateLocalComponent',

0 commit comments

Comments
 (0)