mirror of
https://github.com/un-pany/v3-admin-vite.git
synced 2025-04-16 17:09:20 +08:00
148 lines
4.3 KiB
TypeScript
148 lines
4.3 KiB
TypeScript
/// <reference types="vitest/config" />
|
|
|
|
import { resolve } from "node:path"
|
|
import vue from "@vitejs/plugin-vue"
|
|
import vueJsx from "@vitejs/plugin-vue-jsx"
|
|
import UnoCSS from "unocss/vite"
|
|
import AutoImport from "unplugin-auto-import/vite"
|
|
import SvgComponent from "unplugin-svg-component/vite"
|
|
import { ElementPlusResolver } from "unplugin-vue-components/resolvers"
|
|
import Components from "unplugin-vue-components/vite"
|
|
import { defineConfig, loadEnv } from "vite"
|
|
import svgLoader from "vite-svg-loader"
|
|
|
|
// Configuring Vite: https://cn.vite.dev/config
|
|
export default defineConfig(({ mode }) => {
|
|
const { VITE_PUBLIC_PATH } = loadEnv(mode, process.cwd(), "") as ImportMetaEnv
|
|
return {
|
|
// 开发或打包构建时用到的公共基础路径
|
|
base: VITE_PUBLIC_PATH,
|
|
resolve: {
|
|
alias: {
|
|
// @ 符号指向 src 目录
|
|
"@": resolve(__dirname, "src"),
|
|
// @@ 符号指向 src/common 通用目录
|
|
"@@": resolve(__dirname, "src/common")
|
|
}
|
|
},
|
|
// 开发环境服务器配置
|
|
server: {
|
|
// 是否监听所有地址
|
|
host: true,
|
|
// 端口号
|
|
port: 3333,
|
|
// 端口被占用时,是否直接退出
|
|
strictPort: false,
|
|
// 是否自动打开浏览器
|
|
open: true,
|
|
// 反向代理
|
|
proxy: {
|
|
"/api/v1": {
|
|
target: "https://apifoxmock.com/m1/2930465-2145633-default",
|
|
// 是否为 WebSocket
|
|
ws: false,
|
|
// 是否允许跨域
|
|
changeOrigin: true
|
|
}
|
|
},
|
|
// 是否允许跨域
|
|
cors: true,
|
|
// 预热常用文件,提高初始页面加载速度
|
|
warmup: {
|
|
clientFiles: [
|
|
"./src/layouts/**/*.*",
|
|
"./src/pinia/**/*.*",
|
|
"./src/router/**/*.*"
|
|
]
|
|
}
|
|
},
|
|
// 构建配置
|
|
build: {
|
|
// 自定义底层的 Rollup 打包配置
|
|
rollupOptions: {
|
|
output: {
|
|
/**
|
|
* @name 分块策略
|
|
* @description 1. 注意这些包名必须存在,否则打包会报错
|
|
* @description 2. 如果你不想自定义 chunk 分割策略,可以直接移除这段配置
|
|
*/
|
|
manualChunks: {
|
|
vue: ["vue", "vue-router", "pinia"],
|
|
element: ["element-plus", "@element-plus/icons-vue"],
|
|
vxe: ["vxe-table"]
|
|
}
|
|
}
|
|
},
|
|
// 是否开启 gzip 压缩大小报告,禁用时能略微提高构建性能
|
|
reportCompressedSize: false,
|
|
// 单个 chunk 文件的大小超过 2048kB 时发出警告
|
|
chunkSizeWarningLimit: 2048
|
|
},
|
|
// 混淆器
|
|
esbuild:
|
|
mode === "development"
|
|
? undefined
|
|
: {
|
|
// 打包构建时移除 console.log
|
|
pure: ["console.log"],
|
|
// 打包构建时移除 debugger
|
|
drop: ["debugger"],
|
|
// 打包构建时移除所有注释
|
|
legalComments: "none"
|
|
},
|
|
// 插件配置
|
|
plugins: [
|
|
vue(),
|
|
// 支持 JSX、TSX 语法
|
|
vueJsx(),
|
|
// 支持将 SVG 文件导入为 Vue 组件
|
|
svgLoader({
|
|
defaultImport: "url",
|
|
svgoConfig: {
|
|
plugins: [
|
|
{
|
|
name: "preset-default",
|
|
params: {
|
|
overrides: {
|
|
// @see https://github.com/svg/svgo/issues/1128
|
|
removeViewBox: false
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}),
|
|
// 自动生成 SvgIcon 组件和 SVG 雪碧图
|
|
SvgComponent({
|
|
iconDir: [resolve(__dirname, "src/common/assets/icons")],
|
|
preserveColor: resolve(__dirname, "src/common/assets/icons/preserve-color"),
|
|
dts: true,
|
|
dtsDir: resolve(__dirname, "types/auto")
|
|
}),
|
|
// 原子化 CSS
|
|
UnoCSS(),
|
|
// 自动按需导入 API
|
|
AutoImport({
|
|
imports: ["vue", "vue-router", "pinia"],
|
|
dts: "types/auto/auto-imports.d.ts",
|
|
resolvers: [ElementPlusResolver()]
|
|
}),
|
|
// 自动按需导入组件
|
|
Components({
|
|
dts: "types/auto/components.d.ts",
|
|
resolvers: [ElementPlusResolver()]
|
|
})
|
|
],
|
|
// Configuring Vitest: https://cn.vitest.dev/config
|
|
test: {
|
|
include: ["tests/**/*.test.{ts,js}"],
|
|
environment: "happy-dom",
|
|
server: {
|
|
deps: {
|
|
inline: ["element-plus"]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|