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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 66 additions & 0 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy