安装插件
npm install unplugin-vue-components -D
vite.config.ts
(以NaiveUi
为例):
import vue from '@vitejs/plugin-vue'
import path from 'path'
import ViteComponents from 'unplugin-vue-components/vite'
import {NaiveUiResolver} from 'unplugin-vue-components/resolvers'
export default () => {
return {
base: '/',
plugins: [
vue(),
ViteComponents({
resolvers: [NaiveUiResolver()],
}),
],
resolve: {
alias: [{
find: '@',
replacement: path.resolve(__dirname, 'src'),
},
]
},
server: {
open: true,
},
}
}