使用 unplugin-vue-components
插件,它可以自动引入组件,并按需引入组件的样式
1、安装插件
npm i unplugin-vue-components -D
2、vite.config.js
文件中配置插件
import { fileURLToPath, URL } from 'node:url' import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import Components from 'unplugin-vue-components/vite'; import { VantResolver } from 'unplugin-vue-components/resolvers'; export default defineConfig({ plugins: [ vue(), Components({ resolvers: [VantResolver()], }) ], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } } })
标签:插件,vue,vant,unplugin,components,组件,import,加载 From: https://www.cnblogs.com/aoshuang/p/18207657