You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+84-6
Original file line number
Diff line number
Diff line change
@@ -60,9 +60,33 @@ module.exports = {
60
60
61
61
### Loader Inference
62
62
63
-
`vue-loader` 15 no longer infers the loader to use based on the `lang` attribute. Instead, the plugin dynamically creates rules that clones your existing config and maps them to vue language block requests. So, in the new version, in order to use SASS loader, you will need to explicitly configure the loader to use like in the example above.
63
+
`vue-loader` 15 now infers loaders to use for language blocks a bit differently.
64
64
65
-
The benefit is now your plain SASS imports from JavaScript and all `<style lang="scss">` code inside Vue components share exactly the same loaders and options. In the past, if `vue-loader`'s default behavior doesn't match your needs, you'd have to duplicate the config using `vue-loader`'s own `loaders` option, but now it is no longer needed.
65
+
Take `<style lang="less">` as an example: in v14 and below, it will attempt to load the block with `less-loader`, and implicitly chains `css-loader` and `vue-style-loader` after it, all using inline loader strings.
66
+
67
+
In v15, `<style lang="less">` will behave as if it's an actual `*.less` file being loaded. So, in order to process it, you need to provide an explicit rule in your main webpack config:
68
+
69
+
```js
70
+
{
71
+
module: {
72
+
rules: [
73
+
// ...other rules
74
+
{
75
+
test:/\.less$/,
76
+
use: [
77
+
'vue-style-loader',
78
+
'css-loader',
79
+
'less-loader'
80
+
]
81
+
}
82
+
]
83
+
}
84
+
}
85
+
```
86
+
87
+
The benefit is that this same rule also applies to plain `*.less` imports from JavaScript, and you can configure options for these loaders anyway you want. In v14 and below, if you want to provide custom options to an inferred loader, you'd have to duplicate it under `vue-loader`'s own `loaders` option. In v15 it is no longer necessary.
88
+
89
+
v15 also allows using non-serializable options for loaders, which was not possible in previous versions.
66
90
67
91
### Style Injection
68
92
@@ -72,15 +96,39 @@ Note the injection order is still not guaranteed, so you should avoid writing CS
72
96
73
97
### PostCSS
74
98
75
-
`vue-loader` no longer auto applies PostCSS transforms. To use PostCSS, configure `postcss-loader` the same way you would for plain CSS outside `*.vue` files.
99
+
`vue-loader` no longer auto applies PostCSS transforms. To use PostCSS, configure `postcss-loader` the same way you would for normal CSS files.
76
100
77
101
### CSS Modules
78
102
79
-
CSS Modules now need to be explicitly configured in main webpack config's `css-loader` options. The `module` attribute on `<style>` tags are still needed for locals injection into the component.
103
+
CSS Modules now need to be explicitly configured via `css-loader` options. The `module` attribute on `<style>` tags is still needed for locals injection into the component.
80
104
81
-
The good news is that you can now configure `localIdentName` in one place.
105
+
The good news is that you can now configure `localIdentName` in one place:
82
106
83
-
If you still want the ability to only use CSS Modules in some of your Vue components, you can use a `oneOf` rule and check for the `cssModules` string in resourceQuery:
107
+
```js
108
+
{
109
+
module: {
110
+
rules: [
111
+
{
112
+
test:/\.css$/,
113
+
use: [
114
+
{
115
+
loader:'vue-style-loader'
116
+
},
117
+
{
118
+
loader:'css-loader',
119
+
options: {
120
+
modules:true,
121
+
localIdentName:'[local]_[hash:base64:8]'
122
+
}
123
+
}
124
+
]
125
+
}
126
+
]
127
+
}
128
+
}
129
+
```
130
+
131
+
If you only want to use CSS Modules in some of your Vue components, you can use a `oneOf` rule and check for the `cssModules` string in resourceQuery:
84
132
85
133
```js
86
134
{
@@ -111,6 +159,36 @@ If you still want the ability to only use CSS Modules in some of your Vue compon
111
159
}
112
160
```
113
161
162
+
## CSS Extraction
163
+
164
+
Works the same way as you'd configure it for normal CSS. Example usage with [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin):
165
+
166
+
```js
167
+
{
168
+
module: {
169
+
rules: [
170
+
{
171
+
test:/\.vue$/,
172
+
use:'vue-loader'
173
+
},
174
+
{
175
+
test:/\.css$/,
176
+
// or ExtractTextWebpackPlugin.extract(...)
177
+
use: [
178
+
MiniCssExtractPlugin.loader,
179
+
'css-loader'
180
+
]
181
+
}
182
+
]
183
+
},
184
+
plugins: [
185
+
newMiniCssExtractPlugin({
186
+
filename:'output.css'
187
+
})
188
+
]
189
+
}
190
+
```
191
+
114
192
## Options Deprecation
115
193
116
194
The following options have been deprecated and should be configured using normal webpack module rules:
0 commit comments