wireguard-dashboard-admin/vite.config.ts

80 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-03-03 23:30:08 +08:00
import dayjs from "dayjs";
2021-10-16 16:16:58 +08:00
import { resolve } from "path";
2022-03-03 23:30:08 +08:00
import pkg from "./package.json";
2021-12-06 17:11:15 +08:00
import { warpperEnv, regExps } from "./build";
2022-02-05 14:45:20 +08:00
import { getPluginsList } from "./build/plugins";
2021-12-06 17:11:15 +08:00
import { UserConfigExport, ConfigEnv, loadEnv } from "vite";
2021-10-16 16:16:58 +08:00
/** 当前执行node命令时文件夹的地址工作目录 */
2021-12-06 17:11:15 +08:00
const root: string = process.cwd();
/** 路径查找 */
2021-10-19 20:37:36 +08:00
const pathResolve = (dir: string): string => {
2021-10-16 16:16:58 +08:00
return resolve(__dirname, ".", dir);
};
/** 设置别名 */
2021-10-16 16:16:58 +08:00
const alias: Record<string, string> = {
"@": pathResolve("src"),
2022-03-14 14:49:02 +08:00
"@build": pathResolve("build")
2021-10-16 16:16:58 +08:00
};
2022-03-03 23:30:08 +08:00
const { dependencies, devDependencies, name, version } = pkg;
const __APP_INFO__ = {
pkg: { dependencies, devDependencies, name, version },
lastBuildTime: dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss")
};
2021-10-16 16:16:58 +08:00
export default ({ command, mode }: ConfigEnv): UserConfigExport => {
2021-12-06 17:11:15 +08:00
const {
VITE_CDN,
2021-12-06 17:11:15 +08:00
VITE_PORT,
2021-12-17 15:09:02 +08:00
VITE_LEGACY,
VITE_COMPRESSION,
2021-12-06 17:11:15 +08:00
VITE_PUBLIC_PATH,
VITE_PROXY_DOMAIN,
VITE_PROXY_DOMAIN_REAL
} = warpperEnv(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: {
// 是否开启 https
https: false,
2021-12-06 17:11:15 +08:00
// 端口号
2021-10-16 16:16:58 +08:00
port: VITE_PORT,
host: "0.0.0.0",
// 本地跨域代理
2021-12-06 17:11:15 +08:00
proxy:
VITE_PROXY_DOMAIN_REAL.length > 0
? {
[VITE_PROXY_DOMAIN]: {
target: VITE_PROXY_DOMAIN_REAL,
// ws: true,
changeOrigin: true,
rewrite: (path: string) => regExps(path, VITE_PROXY_DOMAIN)
}
}
: null
2021-10-16 16:16:58 +08:00
},
plugins: getPluginsList(command, VITE_LEGACY, VITE_CDN, VITE_COMPRESSION),
2021-10-16 16:16:58 +08:00
optimizeDeps: {
2022-08-22 21:34:55 +08:00
include: ["pinia", "vue-i18n", "lodash-es", "@vueuse/core", "dayjs"],
2022-03-17 15:45:11 +08:00
exclude: ["@pureadmin/theme/dist/browser-utils"]
2021-10-16 16:16:58 +08:00
},
build: {
sourcemap: false,
// 消除打包大小超过500kb警告
2022-04-25 18:46:25 +08:00
chunkSizeWarningLimit: 4000
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
}
};
};