unplugin-vue-components (later called plugins) is a plugin that automatically introduces vue components on demand, and is a masterpiece of Antfu.
It is common to bring in component libraries on-demand in order to reduce the project size. However, if you use component library content very frequently in your project, or even need to introduce multiple component libraries, this can become very cumbersome, potentially requiring a dozen components to be imported in a single component and manually added to Components to be used. Such behavior, in a project, may be repeated many times, time-consuming and labor-intensive.
So what problem does the plugin solve? The plugin is based on
unplugin and has support for Vue Components. It can preset conditions to match the components used in the component template, and then automatically introduce them on demand. In addition, you can specify a directory, and the plugin will register the components in the directory, so that they can be used directly in the global scope without importing them.
unplugin-vue-components is more widely supported.
According to the official description.
- Support for Vue 2 and Vue 3
- Support for components and directives
- Support for Vite, Webpack, Vue CLI, Rollup, esbuild, etc., which depends on what unplugin supports.
- Support for tree-shaking, importing only the components used
- Full support for TypeScript
- Built-in parsing support for many popular component libraries, such as Ant Design Vue 3, which I need to use
For more information, please visit antfu/unplugin-auto-import.
Automatically import UI libraries
Here we use vite as an example.
Now you can use Ant Design Vue components freely in your project, the plugin will automatically match and introduce the corresponding components and style files, which can be said to be a very good experience, which is the recommended way to use Ant Design Vue at this stage.
Automatically import components
If TypeScript is installed, the plugin will automatically turn on the dts option, generating the
Be careful not to have duplicate components, as they will be automatically ignored to prevent conflicts.
Full configuration item definition