first commit

This commit is contained in:
2026-09-02 16:31:50 +08:00
commit a461727193
911 changed files with 692450 additions and 0 deletions
+112
View File
@@ -0,0 +1,112 @@
/// <reference types="vitest" />
import { type ConfigEnv, type UserConfigExport, loadEnv } from "vite"
import path, { resolve } from "path"
import vue from "@vitejs/plugin-vue"
import vueJsx from "@vitejs/plugin-vue-jsx"
import { createSvgIconsPlugin } from "vite-plugin-svg-icons"
import svgLoader from "vite-svg-loader"
import UnoCSS from "unocss/vite"
/** 配置项文档:https://cn.vitejs.dev/config */
export default (configEnv: ConfigEnv): UserConfigExport => {
const viteEnv = loadEnv(configEnv.mode, process.cwd()) as ImportMetaEnv
const { VITE_PUBLIC_PATH } = viteEnv
return {
/** 打包时根据实际情况修改 base */
base: VITE_PUBLIC_PATH,
resolve: {
alias: {
/** @ 符号指向 src 目录 */
"@": resolve(__dirname, "./src")
}
},
server: {
/** 是否开启 HTTPS */
https: false,
/** 设置 host: true 才可以使用 Network 的形式,以 IP 访问项目 */
host: true, // host: "0.0.0.0"
/** 端口号 */
port: 3434,
/** 是否自动打开浏览器 */
open: true,
/** 跨域设置允许 */
cors: true,
/** 端口被占用时,是否直接退出 */
strictPort: false,
/** 接口代理 */
proxy: {
"/api/v1": {
// target: "https://mock.mengxuegu.com/mock/63218b5fb4c53348ed2bc212",
target: "https://www.fastmock.site/mock/761e2dda2b8890ab86c928a74e8f6538",
ws: true,
/** 是否允许跨域 */
changeOrigin: true
}
}
},
build: {
/** 单个 chunk 文件的大小超过 2048KB 时发出警告 */
chunkSizeWarningLimit: 2048,
/** 禁用 gzip 压缩大小报告 */
reportCompressedSize: false,
/** 打包后静态资源目录 */
assetsDir: "static",
rollupOptions: {
output: {
/**
* 分块策略
* 1. 注意这些包名必须存在,否则打包会报错
* 2. 如果你不想自定义 chunk 分割策略,可以直接移除这段配置
*/
manualChunks: {
vue: ["vue", "vue-router", "pinia"],
element: ["element-plus", "@element-plus/icons-vue"],
vxe: ["vxe-table", "vxe-table-plugin-element", "xe-utils"]
},
// 用于输出静态资源的命名放到dist中的static文件夹下,[ext]表示文件扩展名
assetFileNames: (assetInfo) => {
const info = assetInfo.name.split(".")
let extType = info[info.length - 1]
if (/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/i.test(assetInfo.name)) {
extType = "media"
} else if (/\.(png|jpe?g|gif|svg)(\?.*)?$/.test(assetInfo.name)) {
extType = "img"
} else if (/\.(woff2?|eot|ttf|otf)(\?.*)?$/i.test(assetInfo.name)) {
extType = "fonts"
}
return `static/${extType}/[name]-[hash][extname]`
}
}
}
},
/** 混淆器 */
esbuild: {
/** 打包时移除 console.log */
pure: ["console.log"],
/** 打包时移除 debugger */
drop: ["debugger"],
/** 打包时移除所有注释 */
legalComments: "none"
},
/** Vite 插件 */
plugins: [
vue(),
vueJsx(),
/** 将 SVG 静态图转化为 Vue 组件 */
svgLoader({ defaultImport: "url" }),
/** SVG */
createSvgIconsPlugin({
iconDirs: [path.resolve(process.cwd(), "src/icons/svg")],
symbolId: "icon-[dir]-[name]"
}),
/** UnoCSS */
UnoCSS()
],
/** Vitest 单元测试配置:https://cn.vitest.dev/config */
test: {
include: ["tests/**/*.test.ts"],
environment: "jsdom"
}
}
}