wireguard-dashboard-admin/vite.config.ts

68 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

2022-02-05 14:45:20 +08:00
import { getPluginsList } from "./build/plugins";
2022-11-30 16:33:46 +08:00
import { include, exclude } from "./build/optimize";
2024-03-09 16:27:52 +08:00
import { type UserConfigExport, type ConfigEnv, loadEnv } from "vite";
import {
root,
alias,
2024-05-10 12:09:23 +08:00
wrapperEnv,
2024-03-09 16:27:52 +08:00
pathResolve,
__APP_INFO__
} from "./build/utils";
2021-10-16 16:16:58 +08:00
2024-03-09 16:27:52 +08:00
export default ({ mode }: ConfigEnv): UserConfigExport => {
2022-11-26 19:14:08 +08:00
const { VITE_CDN, VITE_PORT, VITE_COMPRESSION, VITE_PUBLIC_PATH } =
2024-05-10 12:09:23 +08:00
wrapperEnv(loadEnv(mode, root));
2021-10-16 16:16:58 +08:00
return {
2021-12-06 17:11:15 +08:00
base: VITE_PUBLIC_PATH,
2021-10-16 16:16:58 +08:00
root,
resolve: {
alias
},
// 服务端渲染
server: {
2021-12-06 17:11:15 +08:00
// 端口号
2021-10-16 16:16:58 +08:00
port: VITE_PORT,
host: "0.0.0.0",
2022-11-10 12:28:10 +08:00
// 本地跨域代理 https://cn.vitejs.dev/config/server-options.html#server-proxy
proxy: {
"/api": {
target: "http://127.0.0.1:9703",
changeOrigin: true
}
},
2024-03-09 16:27:52 +08:00
// 预热文件以提前转换和缓存结果,降低启动期间的初始页面加载时长并防止转换瀑布
warmup: {
clientFiles: ["./index.html", "./src/{views,components}/*"]
}
2021-10-16 16:16:58 +08:00
},
2024-03-09 16:27:52 +08:00
plugins: getPluginsList(VITE_CDN, VITE_COMPRESSION),
2022-11-26 19:14:08 +08:00
// https://cn.vitejs.dev/config/dep-optimization-options.html#dep-optimization-options
2021-10-16 16:16:58 +08:00
optimizeDeps: {
2022-11-26 19:14:08 +08:00
include,
2022-11-30 16:33:46 +08:00
exclude
2021-10-16 16:16:58 +08:00
},
build: {
2024-03-09 16:27:52 +08:00
// https://cn.vitejs.dev/guide/build.html#browser-compatibility
target: "es2015",
2021-10-16 16:16:58 +08:00
sourcemap: false,
// 消除打包大小超过500kb警告
2022-10-27 15:51:06 +08:00
chunkSizeWarningLimit: 4000,
rollupOptions: {
input: {
2024-03-09 16:27:52 +08:00
index: pathResolve("./index.html", import.meta.url)
2022-10-27 15:51:06 +08:00
},
// 静态资源分类打包
output: {
chunkFileNames: "static/js/[name]-[hash].js",
entryFileNames: "static/js/[name]-[hash].js",
assetFileNames: "static/[ext]/[name]-[hash].[ext]"
}
}
2021-10-16 16:16:58 +08:00
},
define: {
2022-03-03 23:30:08 +08:00
__INTLIFY_PROD_DEVTOOLS__: false,
__APP_INFO__: JSON.stringify(__APP_INFO__)
2021-10-16 16:16:58 +08:00
}
};
};