74 lines
2.5 KiB
TypeScript
74 lines
2.5 KiB
TypeScript
import { resolve } from "path"
|
|
import Vue from '@vitejs/plugin-vue'
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
import Components from 'unplugin-vue-components/vite'
|
|
import Unocss from 'unocss/vite'
|
|
import { ElementPlusResolver, ElementPlusResolverOptions } from 'unplugin-vue-components/resolvers'
|
|
|
|
import vitePluginVuedoc, { vueDocFiles } from 'vite-plugin-vuedoc'
|
|
|
|
import composablesFileList from "../src/composables/_fileList"
|
|
import storeFileList from "../src/store/_fileList"
|
|
import componentsFileList from "../src/components/_fileList"
|
|
|
|
const elementPlusConfig:ElementPlusResolverOptions = {
|
|
importStyle: false,
|
|
// version:'2.0.1'
|
|
}
|
|
// 自动引入 自定义文件
|
|
const autoImportImports = {}
|
|
|
|
// 自动引入 composables 目录下的文件
|
|
const compFileList = composablesFileList || [];
|
|
for (let index = 0; index < compFileList.length; index++) {
|
|
autoImportImports[compFileList[index].path] = [ [ 'default', compFileList[index].fileName ] ]
|
|
}
|
|
// 自动引入 store 目录下的文件
|
|
const storeList = storeFileList || [];
|
|
for (let index = 0; index < storeList.length; index++) {
|
|
autoImportImports[storeList[index].path] = [ [ 'default', storeList[index].fileName ] ]
|
|
}
|
|
// 自动引入 组件作为api引入 可以在 script 标签里面使用
|
|
const componentsList = componentsFileList || [];
|
|
for (let index = 0; index < componentsList.length; index++) {
|
|
// 处理文件名 拼接路径 转为大驼峰命名规则 文件夹下的index文件 以文件夹命名
|
|
const fileName = componentsList[index].path.replace(/^@\/components\/|\/index.vue$|.vue$/g,'').split('/').map(e=> e.replace(e[0], e[0].toUpperCase())).join('')
|
|
autoImportImports[componentsList[index].path] = [ [ 'default', fileName ] ]
|
|
}
|
|
|
|
export default () => {
|
|
return [
|
|
vitePluginVuedoc({}),
|
|
Vue({
|
|
// include: [/\.vue$/, /\.md$/]
|
|
include: [...vueDocFiles]
|
|
}),
|
|
Unocss(),
|
|
// 自动导入 组件
|
|
Components({
|
|
include: [/\.vue$/, /\.vue\?vue/],
|
|
exclude: [/[\\/]node_modules[\\/]/, /[\\/]\.git[\\/]/, /[\\/]\.nuxt[\\/]/],
|
|
dts: resolve(__dirname, "./types/components.d.ts"),
|
|
extensions: ['vue'],
|
|
resolvers: [
|
|
ElementPlusResolver(elementPlusConfig)
|
|
],
|
|
directoryAsNamespace: true,
|
|
}),
|
|
// api 自动按需引入
|
|
AutoImport({
|
|
dts: resolve(__dirname, './types/auto-imports.d.ts'),
|
|
imports: [
|
|
'vue',
|
|
'pinia',
|
|
'vue-router',
|
|
"@vueuse/core",
|
|
autoImportImports
|
|
],
|
|
resolvers: [
|
|
ElementPlusResolver(elementPlusConfig),
|
|
]
|
|
}),
|
|
|
|
]
|
|
} |