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

add postcss document; #139

Merged
merged 1 commit into from
Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ rollup.rollup({
'parse5',
'path',
'postcss',
'postcss-load-config',
'postcss-modules',
'postcss-selector-parser',
'posthtml',
Expand Down
66 changes: 66 additions & 0 deletions docs/en/2.3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,72 @@ The output CSS will be like:
}
```

#### PostCSS

<p class="tip">
Available in `rollup-plugin-vue@^2.5+`.
</p>

`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/).

##### Configuration

We use [postcss-load-config](https://github.com/michael-ciniawsky/postcss-load-config) to load config file, that means:
- `postcss` field in your `package.json`
- `.postcssrc` file in JSON or YAML format
- `postcss.config.js` or `.postcssrc.js`

##### Inline Options

You can also use a `postcss` option, it accepts three types:
- `Function`: return an array of plugins
- `Array`: an array of plugins
- `Object`: `postcss`'s configuration, has the most priority

For example, if you want to use `Autoprefixer`, that means something like

``` js
import Autoprefixer from 'autoprefixer'

export default {
...
postcss: [Autoprefixer()],
...
}
```

or

``` js
import Autoprefixer from 'autoprefixer'

export default {
...
postcss() {
return [Autoprefixer()]
},
...
}
```

or this:

``` js
import Autoprefixer from 'autoprefixer'

export default {
...
postcss {
plugins: [Autoprefixer()],
options: {
// postcss's option goes here
...
}
},
...
}
```

### Template
Templates are processed into `render` function by default. You can disable this by setting:
``` js
Expand Down
6 changes: 4 additions & 2 deletions src/style/postcss.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import postcssrc from 'postcss-load-config'

/* eslint-disable complexity */
export default async function (postcssOpt) {
let options = {}
let plugins = []

if (typeof postcssOpt === 'function') {
plugins = postcssOpt.call(this)
} else if (Array.isArray(postcssOpt)) {
plugins = plugins.concat(postcssOpt)
plugins = postcssOpt
} else if (typeof postcssOpt === 'object') {
options = Object.assign({}, options, postcssOpt)
plugins = (typeof postcssOpt.plugins === 'function') ? postcssOpt.plugins.call(this) : postcssOpt.plugins || []
options = postcssOpt.options || {}
}

return postcssrc().then((config) => {
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function test(name) {
modules: {
generateScopedName: '[name]__[local]'
},
postcss: [autoprefixer()],
postcss: { plugins: [autoprefixer()] },
compileTemplate: [
'compileTemplate',
'compileTemplateLocalComponent',
Expand Down