Skip to content

Commit 6af8b3b

Browse files
committed
support user-provided postcss plugins
1 parent 73def6f commit 6af8b3b

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

README.md

+29-11
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default {
3333
- [Basic Usage](#basic-usage)
3434
- [ES2015 by Default](#es2015-by-default)
3535
- [CSS Pre-Processors](#css-pre-processors)
36-
- [Autoprefixing](#autoprefixing)
36+
- [PostCSS](#postcss)
3737
- [Template Pre-Processors](#template-pre-processors)
3838
- [Style Imports](#style-imports)
3939
- [Asset URL Handling](#asset-url-handling)
@@ -133,19 +133,35 @@ You can also include Webpack loader queries in the `lang` attribute:
133133
</style>
134134
```
135135

136-
## Autoprefixing
136+
## PostCSS
137137

138-
Starting in 6.0.0, Any CSS output via `vue-loader` is piped through [autoprefixer](https://github.com/postcss/autoprefixer) by default. You can customize this behavior in the `vue` section of your webpack config:
138+
Any CSS output via `vue-loader` 6.0+ is piped through [PostCSS](https://github.com/postcss/postcss) for [scoped CSS](#scoped-css) rewriting and aut-prefixed by default using [autoprefixer](https://github.com/postcss/autoprefixer). You can configure autoprefixer or provide your own PostCSS plugins in the `vue` section of your webpack config:
139139

140140
``` js
141141
// webpack.config.js
142142
module.exports = {
143143
// other configs...
144144
vue: {
145-
// disable autoprefixing
146-
autoprefixer: false,
147-
// OR: custom options
148-
autoprefixer: { browsers: ['last 2 versions'] }
145+
// configure autoprefixer
146+
autoprefixer: {
147+
browsers: ['last 2 versions']
148+
}
149+
}
150+
}
151+
```
152+
153+
Using other PostCSS plugins:
154+
155+
``` js
156+
// webpack.config.js
157+
module.exports = {
158+
// other configs...
159+
vue: {
160+
// use custom postcss plugins
161+
postcss: [require('cssnext')()],
162+
// disable vue-loader autoprefixing.
163+
// this is a good idea since cssnext comes with it too.
164+
autoprefixer: false
149165
}
150166
}
151167
```
@@ -180,7 +196,7 @@ For more details, see the respective documentations for [vue-html-loader](https:
180196

181197
> Experimental
182198
183-
When a `<style>` tag has the `scoped` attribute, its CSS will apply to elements of the current component only. This is similar to the style encapsulation found in Shadow DOM, but doesn't require any polyfills. It is achieved by transforming the following:
199+
When a `<style>` tag has the `scoped` attribute, its CSS will apply to elements of the current component only. This is similar to the style encapsulation found in Shadow DOM, but doesn't require any polyfills. It is achieved by using PostCSS to transform the following:
184200

185201
``` html
186202
<style scoped>
@@ -197,12 +213,12 @@ Into the following:
197213

198214
``` html
199215
<style>
200-
.example[_v-1] {
216+
.example[_v-f3f3eg9] {
201217
color: red;
202218
}
203219
</style>
204220
<template>
205-
<div class="example" _v-1>hi</div>
221+
<div class="example" _v-f3f3eg9>hi</div>
206222
</template>
207223
```
208224

@@ -212,7 +228,9 @@ Into the following:
212228

213229
2. A child component's root node will be affected by both the parent's scoped CSS and the child's scoped CSS.
214230

215-
3. Partials are not affected by scoped styles.
231+
3. If you are nesting a component inside itself, the styles may still leak down since they are considered the same component.
232+
233+
4. Partials are not affected by scoped styles.
216234

217235
## Hot Reload
218236

lib/style-rewriter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = function (css, map) {
3737
var query = loaderUtils.parseQuery(this.query)
3838
var options = this.options.vue || {}
3939
var autoprefixOptions = options.autoprefixer
40-
var plugins = []
40+
var plugins = options.postcss || []
4141

4242
// scoped css
4343
if (query.scoped) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-loader",
3-
"version": "6.0.4",
3+
"version": "6.0.5",
44
"description": "Vue.js component loader for Webpack",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)