Skip to content

Commit 5cc5c4d

Browse files
committed
refactor!: renamed package to unplugin-vue-components
1 parent 06f8565 commit 5cc5c4d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+469
-329
lines changed

README.md

+74-64
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<h2 align='center'><samp>vite-plugin-components</samp></h2>
1+
<h2 align='center'><samp>unplugin-vue-components</samp></h2>
22

3-
<p align='center'>On demand components auto importing for Vite</p>
3+
<p align='center'>On-demand components auto importing for Vue.<br><sub>Works for Vite, Webpack, Vue CLI and more, powered by <a href="https://github.com/unjs/unplugin">unplugin</a></sub></p>
44

55
<p align='center'>
6-
<a href='https://www.npmjs.com/package/vite-plugin-components'>
7-
<img src='https://img.shields.io/npm/v/vite-plugin-components?color=222&style=flat-square'>
6+
<a href='https://www.npmjs.com/package/unplugin-vue-components'>
7+
<img src='https://img.shields.io/npm/v/unplugin-vue-components?color=222&style=flat-square'>
88
</a>
99
</p>
1010

@@ -20,25 +20,23 @@
2020

2121
## Usage
2222

23-
> ℹ️ **Vite 2 is supported from `v0.6.x`, Vite 1's support is discontinued.**
24-
2523
Install
2624

2725
```bash
28-
npm i vite-plugin-components -D # yarn add vite-plugin-components -D
26+
npm i unplugin-vue-components -D
2927
```
3028

3129
Add it to `vite.config.js`
3230

3331
```ts
3432
// vite.config.js
3533
import Vue from '@vitejs/plugin-vue'
36-
import ViteComponents from 'vite-plugin-components'
34+
import Components from 'unplugin-vue-components/vite'
3735

3836
export default {
3937
plugins: [
4038
Vue(),
41-
ViteComponents()
39+
Components()
4240
],
4341
};
4442
```
@@ -84,24 +82,48 @@ export default {
8482
</script>
8583
```
8684

87-
## TypeScript
85+
## Migrate from `vite-plugin-components`
8886

89-
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`
9088

91-
```ts
92-
// vite.config.js
93-
import ViteComponents from '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'
94104

95105
export default {
96106
plugins: [
97107
/* ... */
98-
ViteComponents({
99-
globalComponentsDeclaration: true,
108+
Components({
109+
customComponentResolvers: [
110+
ElementPlusResolver(),
111+
]
100112
}),
101113
],
102114
}
103115
```
104116

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+
105127
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.
106128

107129
**Make sure you also add `components.d.ts` to your `tsconfig.json` under `includes`.**
@@ -112,13 +134,13 @@ It just works.
112134

113135
```ts
114136
// vite.config.js
115-
import { createVuePlugin } from 'vite-plugin-vue2'
116-
import ViteComponents from 'vite-plugin-components'
137+
import { createVuePlugin as Vue2 } from 'vite-plugin-vue2'
138+
import Components from 'unplugin-vue-components/vite'
117139

118140
export default {
119141
plugins: [
120-
createVuePlugin(),
121-
ViteComponents(),
142+
Vue2(),
143+
Components(),
122144
],
123145
}
124146
```
@@ -129,61 +151,49 @@ We have several built-in resolvers for popular UI libraries like **Vuetify**, **
129151

130152
Supported Resolvers:
131153

132-
- [Ant Design Vue](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/antdv.ts)
133-
- [Element Plus](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/element-plus.ts)
134-
- [Headless UI](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/headless-ui.ts)
135-
- [Naive UI](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/naive-ui.ts)
136-
- [Prime Vue](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/prime-vue.ts)
137-
- [Vant](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/vant.ts)
138-
- [Varlet UI](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/varlet-ui.ts)
139-
- [Vuetify](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/vuetify.ts)
140-
- [VueUse Components](https://github.com/antfu/vite-plugin-components/blob/master/src/resolvers/vueuse.ts)
141-
- [View UI](https://github.com/antfu/vite-plugin-components/blob/main/src/resolvers/view-ui.ts)
142-
- [Element UI](https://github.com/antfu/vite-plugin-components/blob/main/src/resolvers/element-ui.ts)
154+
- [Ant Design Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/antdv.ts)
155+
- [Element Plus](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/element-plus.ts)
156+
- [Headless UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/headless-ui.ts)
157+
- [Naive UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/naive-ui.ts)
158+
- [Prime Vue](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/prime-vue.ts)
159+
- [Vant](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vant.ts)
160+
- [Varlet UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/varlet-ui.ts)
161+
- [Vuetify](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vuetify.ts)
162+
- [VueUse Components](https://github.com/antfu/unplugin-vue-components/blob/main/src/core/resolvers/vueuse.ts)
163+
- [View UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/resolvers/view-ui.ts)
164+
- [Element UI](https://github.com/antfu/unplugin-vue-components/blob/main/src/resolvers/element-ui.ts)
143165

144166
```ts
145167
// vite.config.js
146168
import ViteComponents, {
147169
AntDesignVueResolver,
148170
ElementPlusResolver,
149171
VantResolver,
150-
} from 'vite-plugin-components'
151-
152-
export default {
153-
plugins: [
154-
/* ... */
155-
ViteComponents({
156-
customComponentResolvers: [
157-
AntDesignVueResolver(),
158-
ElementPlusResolver(),
159-
VantResolver(),
160-
]
161-
}),
162-
],
163-
}
172+
} from 'unplugin-vue-components/resolvers'
173+
174+
// your plugin installation
175+
Components({
176+
customComponentResolvers: [
177+
AntDesignVueResolver(),
178+
ElementPlusResolver(),
179+
VantResolver(),
180+
]
181+
})
164182
```
165183

166184
You can also write your own resolver easily:
167185

168186
```ts
169-
// vite.config.js
170-
import ViteComponents from 'vite-plugin-components'
171-
172-
export default {
173-
plugins: [
174-
/* ... */
175-
ViteComponents({
176-
customComponentResolvers: [
177-
// example of importing Vant
178-
(name) => {
179-
// where `name` is always CapitalCase
180-
if (name.startsWith('Van'))
181-
return { importName: name.slice(3), path: 'vant' }
182-
}
183-
]
184-
}),
185-
],
186-
}
187+
Components({
188+
customComponentResolvers: [
189+
// example of importing Vant
190+
(name) => {
191+
// where `name` is always CapitalCase
192+
if (name.startsWith('Van'))
193+
return { importName: name.slice(3), path: 'vant' }
194+
}
195+
]
196+
})
187197
```
188198

189199
If you made other UI libraries configured, please feel free to contribute so it can help others using them out-of-box. Thanks!
@@ -193,7 +203,7 @@ If you made other UI libraries configured, please feel free to contribute so it
193203
The following show the default values of the configuration
194204

195205
```ts
196-
ViteComponents({
206+
Components({
197207
// relative paths to the directory to search for components.
198208
dirs: ['src/components'],
199209

examples/naive-ui/components.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// generated by vite-plugin-components
1+
// generated by unplugin-vue-components
22
// read more https://github.com/vuejs/vue-next/pull/3399
33

44
declare module 'vue' {

examples/naive-ui/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "0.0.0",
44
"private": true,
55
"scripts": {
6-
"dev": "cross-env DEBUG=vite-plugin-components:* vite",
7-
"build": "cross-env DEBUG=vite-plugin-components:* vite build"
6+
"dev": "cross-env DEBUG=unplugin-vue-components:* vite",
7+
"build": "cross-env DEBUG=unplugin-vue-components:* vite build"
88
},
99
"dependencies": {
1010
"naive-ui": "^2.16.4",
@@ -17,7 +17,7 @@
1717
"cross-env": "^7.0.3",
1818
"typescript": "^4.3.5",
1919
"vite": "^2.4.4",
20-
"vite-plugin-components": "workspace:*",
20+
"unplugin-vue-components": "workspace:*",
2121
"vite-plugin-md": "^0.10.0",
2222
"vite-plugin-vue-svg": "^0.1.0"
2323
}

examples/naive-ui/vite.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { UserConfig } from 'vite'
22
import Vue from '@vitejs/plugin-vue'
3-
import ViteComponents, { NaiveUiResolver } from 'vite-plugin-components'
3+
import ViteComponents, { NaiveUiResolver } from 'unplugin-vue-components'
44

55
const config: UserConfig = {
66
plugins: [
File renamed without changes.

examples/vue2/package.json examples/vite-vue2/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"private": true,
33
"scripts": {
4-
"dev": "cross-env DEBUG=vite-plugin-components:* vite",
5-
"build": "cross-env DEBUG=vite-plugin-components:* vite build"
4+
"dev": "cross-env DEBUG=unplugin-vue-components:* vite",
5+
"build": "cross-env DEBUG=unplugin-vue-components:* vite build"
66
},
77
"devDependencies": {
88
"cross-env": "^7.0.3",
99
"vite": "^2.4.4",
10-
"vite-plugin-components": "workspace:*",
10+
"unplugin-vue-components": "workspace:*",
1111
"vite-plugin-vue2": "^1.8.1"
1212
},
1313
"dependencies": {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

examples/vue2/vite.config.ts examples/vite-vue2/vite.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { UserConfig } from 'vite'
22
import { createVuePlugin } from 'vite-plugin-vue2'
3-
import ViteComponents from 'vite-plugin-components'
3+
import ViteComponents from 'unplugin-vue-components'
44

55
const config: UserConfig = {
66
plugins: [

examples/vue3/components.d.ts examples/vite-vue3/components.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// generated by vite-plugin-components
1+
// generated by unplugin-vue-components
22
// read more https://github.com/vuejs/vue-next/pull/3399
33

44
declare module 'vue' {
File renamed without changes.

examples/vue3/package.json examples/vite-vue3/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "0.0.0",
44
"private": true,
55
"scripts": {
6-
"dev": "cross-env DEBUG=vite-plugin-components:* vite",
7-
"build": "cross-env DEBUG=vite-plugin-components:* vite build"
6+
"dev": "cross-env DEBUG=unplugin-vue-components:* vite",
7+
"build": "cross-env DEBUG=unplugin-vue-components:* vite build"
88
},
99
"dependencies": {
1010
"vant": "^3.2.0",
@@ -15,10 +15,11 @@
1515
"@vitejs/plugin-vue": "^1.4.0",
1616
"@vue/compiler-sfc": "^3.2.2",
1717
"cross-env": "^7.0.3",
18+
"has-pkg": "^0.0.1",
1819
"typescript": "^4.3.5",
20+
"unplugin-icons": "^0.1.0",
21+
"unplugin-vue-components": "workspace:*",
1922
"vite": "^2.4.4",
20-
"vite-plugin-components": "workspace:*",
21-
"vite-plugin-icons": "^0.6.5",
2223
"vite-plugin-inspect": "^0.0.2",
2324
"vite-plugin-md": "^0.10.0",
2425
"vite-plugin-vue-svg": "^0.1.0"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

examples/vue3/vite.config.ts examples/vite-vue3/vite.config.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import path from 'path'
22
import { UserConfig } from 'vite'
33
import Vue from '@vitejs/plugin-vue'
4-
import ViteComponents, { VantResolver } from 'vite-plugin-components'
4+
import ViteComponents from 'unplugin-vue-components/vite'
5+
import { VantResolver } from 'unplugin-vue-components/resolvers'
56
import Markdown from 'vite-plugin-md'
6-
import Icons, { ViteIconsResolver } from 'vite-plugin-icons'
7+
import Icons from 'unplugin-icons/vite'
8+
import IconsResolver from 'unplugin-icons/resolver'
79
// @ts-expect-error
810
import SVG from 'vite-plugin-vue-svg'
911
import Inspect from 'vite-plugin-inspect'
@@ -25,7 +27,7 @@ const config: UserConfig = {
2527
ViteComponents({
2628
extensions: ['vue', 'md', 'svg'],
2729
directoryAsNamespace: true,
28-
globalComponentsDeclaration: true,
30+
dts: true,
2931
globalNamespaces: ['global'],
3032
importPathTransform: path => path.endsWith('.svg') ? `${path}?component` : undefined,
3133
customLoaderMatcher: path => path.endsWith('.md'),
@@ -35,7 +37,7 @@ const config: UserConfig = {
3537
return '/src/CustomResolved.vue'
3638
},
3739
VantResolver(),
38-
ViteIconsResolver({
40+
IconsResolver({
3941
componentPrefix: 'i',
4042
}),
4143
],

nuxt.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './dist/nuxt'
2+
export { default } from './dist/nuxt'

0 commit comments

Comments
 (0)