Template
1
0
mirror of https://github.com/un-pany/v3-admin-vite.git synced 2025-04-22 11:59:19 +08:00
v3-admin-vite/vite.config.ts

119 lines
3.4 KiB
TypeScript
Raw Normal View History

2024-11-19 18:31:03 +08:00
/// <reference types="vitest/config" />
2023-02-16 17:36:47 +08:00
2024-11-20 15:18:27 +08:00
import { resolve } from "node:path"
import vue from "@vitejs/plugin-vue"
import vueJsx from "@vitejs/plugin-vue-jsx"
2024-11-18 19:40:44 +08:00
import UnoCSS from "unocss/vite"
2024-11-20 15:18:27 +08:00
import { defineConfig, loadEnv } from "vite"
import { createSvgIconsPlugin } from "vite-plugin-svg-icons"
2022-09-29 22:38:27 +08:00
import svgLoader from "vite-svg-loader"
2022-04-20 22:40:26 +08:00
2024-11-20 15:18:27 +08:00
// Configuring Vite: https://cn.vite.dev/config
export default defineConfig(({ mode }) => {
const root = process.cwd()
const { VITE_PUBLIC_PATH } = loadEnv(mode, root, "") as ImportMetaEnv
2022-04-21 00:50:12 +08:00
return {
2024-11-20 15:18:27 +08:00
// 开发或打包构建时用到的公共基础路径
base: VITE_PUBLIC_PATH,
2022-04-21 00:50:12 +08:00
resolve: {
alias: {
2024-11-19 20:14:23 +08:00
// @ 符号指向 src 目录
2024-11-20 15:18:27 +08:00
"@": resolve(__dirname, "src")
}
2022-04-21 00:50:12 +08:00
},
2024-11-20 15:18:27 +08:00
// 开发环境服务器配置
server: {
2024-11-20 15:18:27 +08:00
// 是否监听所有地址
host: true,
2024-11-19 20:14:23 +08:00
// 端口号
2022-04-28 15:38:49 +08:00
port: 3333,
2024-11-19 20:14:23 +08:00
// 端口被占用时,是否直接退出
strictPort: false,
2024-11-20 15:18:27 +08:00
// 是否自动打开浏览器
open: false,
// 反向代理
proxy: {
"/api/v1": {
2024-02-07 10:38:12 +08:00
target: "https://mock.mengxuegu.com/mock/63218b5fb4c53348ed2bc212",
// 是否为 WebSocket
ws: false,
2024-11-19 20:14:23 +08:00
// 是否允许跨域
2023-08-07 09:34:11 +08:00
changeOrigin: true
}
},
2024-11-20 15:18:27 +08:00
// 是否允许跨域
cors: true,
2024-11-19 20:14:23 +08:00
// 预热常用文件,提高初始页面加载速度
warmup: {
2023-12-12 19:01:25 +08:00
clientFiles: ["./src/layouts/**/*.vue"]
}
},
2024-11-20 15:18:27 +08:00
// 构建配置
build: {
2024-11-20 15:18:27 +08:00
// 自定义底层的 Rollup 打包配置
2023-08-23 11:59:22 +08:00
rollupOptions: {
output: {
/**
* @name
* @description 1.
* @description 2. chunk
*/
2023-08-23 11:59:22 +08:00
manualChunks: {
vue: ["vue", "vue-router", "pinia"],
element: ["element-plus", "@element-plus/icons-vue"],
2023-08-23 11:59:22 +08:00
vxe: ["vxe-table", "vxe-table-plugin-element", "xe-utils"]
}
}
2024-11-20 15:18:27 +08:00
},
// 是否开启 gzip 压缩大小报告,禁用时能略微提高构建性能
reportCompressedSize: false,
// 单个 chunk 文件的大小超过 2048kB 时发出警告
chunkSizeWarningLimit: 2048
2023-08-23 11:59:22 +08:00
},
2024-11-19 20:14:23 +08:00
// 混淆器
esbuild:
mode === "development"
? undefined
: {
2024-11-20 15:18:27 +08:00
// 打包构建时移除 console.log
pure: ["console.log"],
2024-11-20 15:18:27 +08:00
// 打包构建时移除 debugger
drop: ["debugger"],
2024-11-20 15:18:27 +08:00
// 打包构建时移除所有注释
legalComments: "none"
},
2024-11-20 15:18:27 +08:00
// 插件配置
2022-04-21 12:22:35 +08:00
plugins: [
vue(),
2024-11-20 15:18:27 +08:00
// 支持 JSX、TSX 语法
vueJsx(),
2024-11-20 15:18:27 +08:00
// 将 SVG 文件转化为 Vue 组件
svgLoader({ defaultImport: "url" }),
2024-11-20 15:18:27 +08:00
// 生成 SVG 雪碧图
2022-04-21 17:14:30 +08:00
createSvgIconsPlugin({
iconDirs: [resolve(root, "src/assets/icons")],
symbolId: "icon-[dir]-[name]",
// 自定义 SVGO 配置
svgoOptions: {
plugins: [
// 移除 fill 属性
{
name: "removeAttrs",
params: {
attrs: "fill"
}
}
]
}
2022-05-12 19:07:54 +08:00
}),
2024-11-20 15:18:27 +08:00
// 原子化 CSS
UnoCSS()
2023-02-16 17:36:47 +08:00
],
2024-11-20 15:18:27 +08:00
// Configuring Vitest: https://cn.vitest.dev/config
2023-02-16 17:36:47 +08:00
test: {
include: ["tests/**/*.test.{ts,js}"],
2023-02-16 17:36:47 +08:00
environment: "jsdom"
}
2022-04-21 00:50:12 +08:00
}
2024-11-20 15:18:27 +08:00
})