wireguard-dashboard-admin/vite.config.ts

76 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";
2022-11-10 12:28:10 +08:00
import { warpperEnv } from "./build";
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";
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 => {
2022-11-26 19:14:08 +08:00
const { VITE_CDN, VITE_PORT, VITE_COMPRESSION, VITE_PUBLIC_PATH } =
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",
2022-11-10 12:28:10 +08:00
// 本地跨域代理 https://cn.vitejs.dev/config/server-options.html#server-proxy
proxy: {}
2021-10-16 16:16:58 +08:00
},
2022-11-26 19:14:08 +08:00
plugins: getPluginsList(command, VITE_CDN, VITE_COMPRESSION),
// 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: {
sourcemap: false,
// 消除打包大小超过500kb警告
2022-10-27 15:51:06 +08:00
chunkSizeWarningLimit: 4000,
rollupOptions: {
input: {
index: pathResolve("index.html")
},
// 静态资源分类打包
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
}
};
};