Vue Components Auto-Importer

32.0.0 · active · verified Sun Apr 19

unplugin-vue-components is an unplugin-powered build tool plugin that provides on-demand auto-importing for Vue 3 components and directives. It eliminates the need for manual `import` statements and component registrations, simplifying development workflows and enabling automatic code-splitting for asynchronously loaded parent components. The current stable version is 32.0.0, released in April 2026. The project maintains a frequent release cadence, with minor and patch versions released regularly (often weekly or bi-weekly) and major versions introducing breaking changes every few months. Its key differentiators include broad build tool support (Vite, Webpack, Rollup, Rolldown, esbuild, Rspack) via the `unplugin` ecosystem, tree-shakability, built-in resolvers for popular UI libraries, folder-based namespaces, and full TypeScript support, including generated type declarations. It also integrates well with `unplugin-icons` for icon auto-importing.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates configuring `unplugin-vue-components` with Vite and Vue 3, including how to set up component scanning, use UI library resolvers (like Element Plus), and enable TypeScript declaration generation. It also shows common configuration options for directories, inclusions, and exclusions.

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';

export default defineConfig({
  plugins: [
    vue(),
    Components({
      // Specify a path to automatically scan components (e.g., your local `src/components` folder)
      dirs: ['src/components'],
      // Automatically register components from popular UI libraries using resolvers
      resolvers: [
        ElementPlusResolver(), // Example: auto-import Element Plus components
        // Add other resolvers as needed, e.g., AntDesignVueResolver(), VantResolver(), etc.
      ],
      // Generate `components.d.ts` global type declarations for TypeScript support
      dts: true,
      // Allow use of `defineOptions` and `defineModels` within components (Vue 3.3+)
      allowAsProps: true,
      // Custom transformers (e.g., for custom directives or specific component patterns)
      transformers: [],
      // Filter for files that should be processed by the plugin
      include: [/\.vue$/, /\u005c.vue\u005c?vue/],
      // Exclude files/directories to avoid processing (e.g., node_modules, build outputs)
      exclude: [/[\\/]node_modules[\\/]/, /[\\/]\u005c.git[\\/]/, /[\\/]\u005c.nuxt[\\/]/]
    })
  ]
});

view raw JSON →