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'>Ondemand components auto importing for Vite</p>
3
+
<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>
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.
87
+
`package.json`
90
88
91
-
```ts
92
-
// vite.config.js
93
-
importViteComponentsfrom'vite-plugin-components'
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'
94
104
95
105
export default {
96
106
plugins: [
97
107
/* ... */
98
-
ViteComponents({
99
-
globalComponentsDeclaration: true,
108
+
Components({
109
+
customComponentResolvers: [
110
+
ElementPlusResolver(),
111
+
]
100
112
}),
101
113
],
102
114
}
103
115
```
104
116
117
+
## TypeScript
118
+
119
+
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
+
121
+
```ts
122
+
Components({
123
+
dts: true, // enabled by default if `typescript is installed
124
+
})
125
+
```
126
+
105
127
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.
106
128
107
129
**Make sure you also add `components.d.ts` to your `tsconfig.json` under `includes`.**
0 commit comments