Skip to content

Commit 2e2a6ca

Browse files
committed
readme
1 parent c3b379d commit 2e2a6ca

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

README.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# vue-loader@next
2+
3+
This is the WIP branch of the next version of `vue-loader`. It uses a fairly different new architecture that is able to apply whatever rules defined in the main webpack config to the language blocks inside a `*.vue` file.
4+
5+
## Example Usage
6+
7+
``` js
8+
// webpack.config.js
9+
const path = require('path')
10+
const { VueLoaderPlugin } = require('vue-loader')
11+
12+
module.exports = {
13+
mode: 'development',
14+
entry: path.resolve(__dirname, './main.js'),
15+
output: {
16+
path: path.resolve(__dirname, 'dist')
17+
},
18+
module: {
19+
rules: [
20+
{
21+
test: /\.vue$/,
22+
loader: 'vue-loader'
23+
},
24+
// this will apply to both plain .js files
25+
// AND <script> blocks in vue files
26+
{
27+
test: /\.js$/,
28+
loader: 'babel-loader'
29+
},
30+
// this will apply to both plain .css files
31+
// AND <style> blocks in vue files
32+
{
33+
test: /\.css$/,
34+
use: [
35+
'vue-style-loader',
36+
'css-loader'
37+
]
38+
},
39+
// this will apply to both plain .scss files
40+
// AND <style lang="scss"> blocks in vue files
41+
{
42+
test: /\.scss$/,
43+
use: [
44+
'vue-style-loader',
45+
'css-loader',
46+
{
47+
loader: 'sass-loader',
48+
options: {
49+
data: '$color: red;'
50+
}
51+
}
52+
]
53+
}
54+
]
55+
},
56+
plugins: [
57+
// make sure to include the plugin for the magic
58+
new VueLoaderPlugin()
59+
]
60+
}
61+
```
62+
63+
## Notable Breaking Changes
64+
65+
### Loader Inference
66+
67+
`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.
68+
69+
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.
70+
71+
### Style Injection
72+
73+
Client-side style injection now injects all styles upfront to ensure consistent behavior between development and extracted mode.
74+
75+
Note the injection order is still not guaranteed, so you should avoid writing CSS that relies on insertion order.
76+
77+
### CSS Modules
78+
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.
80+
81+
The good news is that you can now configure `localIdentName` in one place.
82+
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:
84+
85+
``` js
86+
{
87+
test: /\.css$/,
88+
oneOf: [
89+
// this matches <style module>
90+
{
91+
resourceQuery: /cssModules/,
92+
use: [
93+
'vue-style-loader',
94+
{
95+
loader: 'css-loader',
96+
options: {
97+
modules: true,
98+
localIdentName: '[local]_[hash:base64:5]'
99+
}
100+
}
101+
]
102+
},
103+
// this matches plain <style> or <style scoped>
104+
{
105+
use: [
106+
'vue-style-loader',
107+
'css-loader'
108+
]
109+
}
110+
]
111+
}
112+
```
113+
114+
## Options Deprecation
115+
116+
The following options have been deprecated and should be configured using normal webpack module rules:
117+
118+
- `loader`
119+
- `preLoaders`
120+
- `postLoaders`
121+
- `postcss`
122+
- `cssSourceMap`
123+
- `buble`
124+
- `extractCSS`
125+
126+
The following options have been deprecated and should be configured using the new `compilerOptions` option:
127+
128+
- `compilerModules`
129+
- `compilerDirectives`
130+
131+
The following option has been renamed:
132+
133+
- `transformToRequire` (now renamed to `transformAssetUrls`)
134+
135+
The following option has been changed to resourceQuery:
136+
137+
- `shadowMode` (now use inline resource queries)
138+
139+
## New Complete Options List
140+
141+
- `compiler`
142+
- `compilerOptions`
143+
- `transformAssetUrls`
144+
- `optimizeSSR`
145+
- `hotReload`

0 commit comments

Comments
 (0)