Skip to content

Commit 6b73b74

Browse files
committed
chore: improve migration
1 parent b8e65f0 commit 6b73b74

File tree

1 file changed

+84
-6
lines changed

1 file changed

+84
-6
lines changed

Diff for: README.md

+84-6
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,33 @@ module.exports = {
6060

6161
### Loader Inference
6262

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.
6464

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.
6690

6791
### Style Injection
6892

@@ -72,15 +96,39 @@ Note the injection order is still not guaranteed, so you should avoid writing CS
7296

7397
### PostCSS
7498

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.
76100

77101
### CSS Modules
78102

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.
80104

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:
82106

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:
84132

85133
``` js
86134
{
@@ -111,6 +159,36 @@ If you still want the ability to only use CSS Modules in some of your Vue compon
111159
}
112160
```
113161

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+
new MiniCssExtractPlugin({
186+
filename: 'output.css'
187+
})
188+
]
189+
}
190+
```
191+
114192
## Options Deprecation
115193

116194
The following options have been deprecated and should be configured using normal webpack module rules:

0 commit comments

Comments
 (0)