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
<palign='center'>On-demand components auto importing for Vue.<br><sub>Works for Vite, Webpack, Vue CLI and more, powered by <ahref="https://github.com/unjs/unplugin">unplugin</a></sub></p>
Use components in templates as you would usually do, it will import components on demand and there is no `import` and `component registration` required anymore! If you register the parent component asynchronously (or lazy route), the auto-imported components will be code-split along with their parent.
47
107
@@ -82,69 +142,20 @@ export default {
82
142
</script>
83
143
```
84
144
85
-
## Migrate from `vite-plugin-components`
86
-
87
-
`package.json`
88
-
89
-
```diff
90
-
{
91
-
"devDependencies": {
92
-
- "vite-plugin-components": "*",
93
-
+ "unplugin-vue-components": "^0.14.0",
94
-
}
95
-
}
96
-
```
97
-
98
-
`vite.config.json`
99
-
100
-
```diff
101
-
- import Components, { ElementPlusResolver } from 'vite-plugin-components'
102
-
+ import Components from 'unplugin-vue-components/vite'
103
-
+ import ElementPlusResolver from 'unplugin-vie-components/resolvers'
104
-
105
-
export default {
106
-
plugins: [
107
-
/* ... */
108
-
Components({
109
-
resolvers: [
110
-
ElementPlusResolver(),
111
-
]
112
-
}),
113
-
],
114
-
}
115
-
```
116
-
117
145
## TypeScript
118
146
119
147
To have TypeScript support for auto-imported components, there is [a PR](https://github.com/vuejs/vue-next/pull/3399) to Vue 3 extending the interface of global components. Currently, [Volar](https://github.com/johnsoncodehk/volar) has supported this usage already, if you are using Volar, you can change the config as following to get the support.
120
148
121
149
```ts
122
150
Components({
123
-
dts: true, // enabled by default if `typescript is installed
151
+
dts: true, // enabled by default if `typescript` is installed
124
152
})
125
153
```
126
154
127
155
Once the setup is done, a `components.d.ts` will be generated and updates automatically with the type definitions. Feel free to commit it into git or not as you want.
128
156
129
157
**Make sure you also add `components.d.ts` to your `tsconfig.json` under `includes`.**
0 commit comments