You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.4 KiB
76 lines
2.4 KiB
import { UserConfig, ConfigEnv, loadEnv, defineConfig} from 'vite'
|
|
import Icons from 'unplugin-icons/vite'
|
|
import IconsResolver from 'unplugin-icons/resolver'
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
import Components from 'unplugin-vue-components/vite'
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'; //SVG精灵图生成插件
|
|
//获取绝对路径
|
|
import path from "path";
|
|
const appPath = path.resolve(__dirname, "src");
|
|
// https://vitejs.dev/config/
|
|
|
|
|
|
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
|
const env = loadEnv(mode, process.cwd());
|
|
return {
|
|
resolve: {
|
|
alias: {
|
|
"@":appPath //@ 表示 src
|
|
}
|
|
},
|
|
server:{
|
|
host: "0.0.0.0",
|
|
port: Number(env.VITE_APP_PORT),
|
|
open: true, // 运行是否自动打开浏览器3647.51 2662.39
|
|
proxy: { // 反向代理解决跨域
|
|
[env.VITE_APP_BASE_API]: {
|
|
target: env.VITE_APP_BASE_URL,
|
|
changeOrigin: true,
|
|
rewrite: (path) => path.replace(new RegExp("^" + env.VITE_APP_BASE_API), "")
|
|
}
|
|
}
|
|
},
|
|
plugins: [
|
|
vue(),
|
|
AutoImport({
|
|
// 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
|
|
imports: ["vue", "@vueuse/core"],
|
|
ignore: ['h'], // 自动添加 import { h } from '/node_modules/.vite/deps/vue.js 代码问题处理
|
|
resolvers: [
|
|
ElementPlusResolver(),
|
|
IconsResolver({
|
|
prefix: 'Icon',
|
|
}),
|
|
],
|
|
vueTemplate: true, // 是否在 vue 模板中自动导入
|
|
dts: path.resolve(appPath, "autoImport", "auto-imports.d.ts"), // 自动导入组件类型声明文件位置,默认根目录; false 关闭自动生成
|
|
}),
|
|
Components({
|
|
resolvers: [
|
|
// 自动注册图标组件
|
|
IconsResolver({
|
|
enabledCollections: ['ep'],
|
|
}),
|
|
ElementPlusResolver()
|
|
],
|
|
dts: path.resolve(appPath, "autoImport", "components.d.ts"), // 自动导入组件类型声明文件位置,默认根目录; false 关闭自动生成
|
|
}),
|
|
createSvgIconsPlugin({
|
|
// 设置图标所在文件夹路径
|
|
iconDirs: [path.resolve(appPath, 'assets/icons')],
|
|
// 设置symbolId的格式
|
|
symbolId: 'icon-[dir]-[name]',
|
|
// (可选)自定义插入位置,默认为body末尾
|
|
// inject: 'body-first',
|
|
// (可选)自定义DOM节点ID,默认为__svg__icons__dom__
|
|
// customDomId: '__my-custom-id__',
|
|
}),
|
|
Icons({
|
|
autoInstall: true,
|
|
}),
|
|
],
|
|
}
|
|
})
|
|
|
|
|