Gathering detailed insights and metrics for unplugin-vue-components
Gathering detailed insights and metrics for unplugin-vue-components
Gathering detailed insights and metrics for unplugin-vue-components
Gathering detailed insights and metrics for unplugin-vue-components
@vuemap/unplugin-resolver
unplugin-vue-components resolvers for @vuemap/vue-amap vue-bmap-gl vue-mapvgl
@vant/auto-import-resolver
Vant auto import resolver based on unplugin-vue-components
@varlet/import-resolver
varlet import resolver for unplugin-vue-components and unplugin-auto-import
@dangojs/unplugin-vue-pro-components-resolver
📲 On-demand components auto importing for Vue
npm install unplugin-vue-components
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (99.92%)
JavaScript (0.08%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4,114 Stars
691 Commits
379 Forks
21 Watchers
1 Branches
154 Contributors
Updated on Jul 15, 2025
Latest Version
28.8.0
Package Id
unplugin-vue-components@28.8.0
Unpacked Size
338.71 kB
Size
85.36 kB
File Count
49
NPM Version
10.9.2
Node Version
22.13.1
Published on
Jun 29, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
On-demand components auto importing for Vue.
1npm i unplugin-vue-components -D
vite-plugin-components
has been renamed tounplugin-vue-components
, see the migration guide.
1// vite.config.ts 2import Components from 'unplugin-vue-components/vite' 3 4export default defineConfig({ 5 plugins: [ 6 Components({ /* options */ }), 7 ], 8})
1// rollup.config.js 2import Components from 'unplugin-vue-components/rollup' 3 4export default { 5 plugins: [ 6 Components({ /* options */ }), 7 ], 8}
1// webpack.config.js 2module.exports = { 3 /* ... */ 4 plugins: [ 5 require('unplugin-vue-components/webpack')({ /* options */ }), 6 ], 7}
1// rspack.config.js 2module.exports = { 3 /* ... */ 4 plugins: [ 5 require('unplugin-vue-components/rspack')({ /* options */ }), 6 ], 7}
1// vue.config.js 2module.exports = { 3 /* ... */ 4 plugins: [ 5 require('unplugin-vue-components/webpack')({ /* options */ }), 6 ], 7}
You can also rename the Vue configuration file to vue.config.mjs
and use static import syntax (you should use latest @vue/cli-service ^5.0.8
):
1// vue.config.mjs 2import Components from 'unplugin-vue-components/webpack' 3 4export default { 5 configureWebpack: { 6 plugins: [ 7 Components({ /* options */ }), 8 ], 9 }, 10}
1// esbuild.config.js 2import { build } from 'esbuild' 3import Components from 'unplugin-vue-components/esbuild' 4 5build({ 6 /* ... */ 7 plugins: [ 8 Components({ 9 /* options */ 10 }), 11 ], 12})
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.
It will automatically turn this
1<template> 2 <div> 3 <HelloWorld msg="Hello Vue 3.0 + Vite" /> 4 </div> 5</template> 6 7<script> 8 export default { 9 name: 'App', 10 } 11</script>
into this
1<template> 2 <div> 3 <HelloWorld msg="Hello Vue 3.0 + Vite" /> 4 </div> 5</template> 6 7<script> 8 import HelloWorld from './src/components/HelloWorld.vue' 9 10 export default { 11 name: 'App', 12 components: { 13 HelloWorld, 14 }, 15 } 16</script>
Note By default this plugin will import components in the
src/components
path. You can customize it using thedirs
option.
To get TypeScript support for auto-imported components, there is a PR to Vue 3 extending the interface of global components. Currently, Volar has supported this usage already. If you are using Volar, you can change the config as following to get the support.
1Components({
2 dts: true, // enabled by default if `typescript` is installed
3})
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.
Make sure you also add
components.d.ts
to yourtsconfig.json
underinclude
.
We have several built-in resolvers for popular UI libraries like Vuetify, Ant Design Vue, and Element Plus, where you can enable them by:
Supported Resolvers:
@vant/auto-import-resolver
- Vant's own auto-import resolver@varlet/import-resolver
- Varlet's own auto-import resolver1import { 2 AntDesignVueResolver, 3 ElementPlusResolver, 4 VantResolver, 5} from 'unplugin-vue-components/resolvers' 6// vite.config.js 7import Components from 'unplugin-vue-components/vite' 8 9// your plugin installation 10Components({ 11 resolvers: [ 12 AntDesignVueResolver(), 13 ElementPlusResolver(), 14 VantResolver(), 15 ], 16})
You can also write your own resolver quickly:
1Components({ 2 resolvers: [ 3 // example of importing Vant 4 (componentName) => { 5 // where `componentName` is always CapitalCase 6 if (componentName.startsWith('Van')) 7 return { name: componentName.slice(3), from: 'vant' } 8 }, 9 ], 10})
Some libraries might register some global components for you to use anywhere (e.g. Vue Router provides <RouterLink>
and <RouterView>
). Since they are global available, there is no need for this plugin to import them. However, those are commonly not TypeScript friendly, and you might need to register their types manually.
Thus unplugin-vue-components
provided a way to only register types for global components.
1Components({ 2 dts: true, 3 types: [{ 4 from: 'vue-router', 5 names: ['RouterLink', 'RouterView'], 6 }], 7})
So the RouterLink
and RouterView
will be presented in components.d.ts
.
By default, unplugin-vue-components
detects supported libraries automatically (e.g. vue-router
) when they are installed in the workspace. If you want to disable it completely, you can pass an empty array to it:
1Components({ 2 // Disable type only registration 3 types: [], 4})
vite-plugin-components
package.json
1{ 2 "devDependencies": { 3- "vite-plugin-components": "*", 4+ "unplugin-vue-components": "^0.14.0", 5 } 6}
vite.config.js
1- import Components, { ElementPlusResolver } from 'vite-plugin-components' 2+ import Components from 'unplugin-vue-components/vite' 3+ import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' 4 5export default { 6 plugins: [ 7 /* ... */ 8 Components({ 9 /* ... */ 10 11 // `customComponentsResolvers` has renamed to `resolver` 12- customComponentsResolvers: [ 13+ resolvers: [ 14 ElementPlusResolver(), 15 ], 16 17 // `globalComponentsDeclaration` has renamed to `dts` 18- globalComponentsDeclaration: true, 19+ dts: true, 20 21 // `customLoaderMatcher` is depreacted, use `include` instead 22- customLoaderMatcher: id => id.endsWith('.md'), 23+ include: [/\.vue$/, /\.vue\?vue/, /\.vue\.[tj]sx?\?vue/, /\.md$/], 24 }), 25 ], 26}
The following show the default values of the configuration
1Components({
2 // relative paths to the directory to search for components.
3 dirs: ['src/components'],
4
5 // valid file extensions for components.
6 extensions: ['vue'],
7
8 // Glob patterns to match file names to be detected as components.
9 // You can also specify multiple like this: `src/components/*.{vue,tsx}`
10 // When specified, the `dirs`, `extensions`, and `directoryAsNamespace` options will be ignored.
11 // If you want to exclude components being registered, use negative globs with leading `!`.
12 globs: ['src/components/*.vue'],
13
14 // search for subdirectories
15 deep: true,
16
17 // resolvers for custom components
18 resolvers: [],
19
20 // generate `components.d.ts` global declarations,
21 // also accepts a path for custom filename
22 // default: `true` if package typescript is installed
23 dts: false,
24
25 // Allow subdirectories as namespace prefix for components.
26 directoryAsNamespace: false,
27
28 // Collapse same prefixes (camel-sensitive) of folders and components
29 // to prevent duplication inside namespaced component name.
30 // works when `directoryAsNamespace: true`
31 collapseSamePrefixes: false,
32
33 // Subdirectory paths for ignoring namespace prefixes.
34 // works when `directoryAsNamespace: true`
35 globalNamespaces: [],
36
37 // auto import for directives
38 // default: `true` for Vue 3, `false` for Vue 2
39 // Babel is needed to do the transformation for Vue 2, it's disabled by default for performance concerns.
40 // To install Babel, run: `npm install -D @babel/parser`
41 directives: true,
42
43 // Transform path before resolving
44 importPathTransform: v => v,
45
46 // Allow for components to override other components with the same name
47 allowOverrides: false,
48
49 // Filters for transforming targets (components to insert the auto import)
50 // Note these are NOT about including/excluding components registered - use `globs` or `excludeNames` for that
51 include: [/\.vue$/, /\.vue\?vue/, /\.vue\.[tj]sx?\?vue/],
52 exclude: [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/],
53
54 // Filters for component names that will not be imported
55 // Use for globally imported async components or other conflicts that the plugin cannot detect
56 excludeNames: [/^Async.+/],
57
58 // Vue version of project. It will detect automatically if not specified.
59 // Acceptable value: 2 | 2.7 | 3
60 version: 2.7,
61
62 // Only provide types of components in library (registered globally)
63 types: []
64})
Vitesse starter template.
Thanks to @brattonross, this project is heavily inspired by vite-plugin-voie.
MIT License © 2020-PRESENT Anthony Fu
No vulnerabilities found.
No security vulnerabilities found.