vue-pure-admin2/vite.config.ts

78 lines
2.0 KiB
TypeScript
Raw Normal View History

2022-03-02 20:47:14 +08:00
import dayjs from "dayjs";
2021-08-31 11:50:39 +08:00
import { resolve } from "path";
2022-03-02 20:47:14 +08:00
import pkg from "./package.json";
2021-12-04 01:16:50 +08:00
import { warpperEnv, regExps } from "./build";
2022-02-05 17:34:01 +08:00
import { getPluginsList } from "./build/plugins";
2021-12-04 01:16:50 +08:00
import { UserConfigExport, ConfigEnv, loadEnv } from "vite";
2021-03-01 15:26:05 +08:00
/** 当前执行node命令时文件夹的地址工作目录 */
2021-12-04 01:16:50 +08:00
const root: string = process.cwd();
/** 路径查找 */
2021-10-19 18:58:47 +08:00
const pathResolve = (dir: string): string => {
2021-08-31 11:50:39 +08:00
return resolve(__dirname, ".", dir);
};
2021-03-01 15:26:05 +08:00
/** 设置别名 */
2021-03-01 15:26:05 +08:00
const alias: Record<string, string> = {
2021-04-21 23:20:14 +08:00
"/@": pathResolve("src"),
2022-03-11 21:28:43 +08:00
"@build": pathResolve("build")
2021-08-31 11:50:39 +08:00
};
2021-03-01 15:26:05 +08:00
2022-03-02 20:47:14 +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")
};
export default ({ command, mode }: ConfigEnv): UserConfigExport => {
2021-12-04 01:16:50 +08:00
const {
VITE_PORT,
VITE_LEGACY,
2021-12-04 01:16:50 +08:00
VITE_PUBLIC_PATH,
VITE_PROXY_DOMAIN,
VITE_PROXY_DOMAIN_REAL
} = warpperEnv(loadEnv(mode, root));
return {
2021-12-04 01:16:50 +08:00
base: VITE_PUBLIC_PATH,
root,
resolve: {
2021-07-07 13:33:47 +08:00
alias
},
// 服务端渲染
server: {
// 是否开启 https
https: false,
2021-12-04 01:16:50 +08:00
// 端口号
port: VITE_PORT,
2021-07-22 11:33:45 +08:00
host: "0.0.0.0",
// 本地跨域代理
2021-12-04 01:16:50 +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
},
2022-02-05 17:34:01 +08:00
plugins: getPluginsList(command, VITE_LEGACY),
2021-04-21 23:20:14 +08:00
optimizeDeps: {
2022-07-18 16:07:03 +08:00
include: ["pinia", "vue-i18n", "lodash-es", "@vueuse/core", "dayjs"],
2022-03-17 15:52:01 +08:00
exclude: ["@pureadmin/theme/dist/browser-utils"]
2021-04-21 23:20:14 +08:00
},
build: {
2021-08-27 01:33:57 +08:00
sourcemap: false,
// 消除打包大小超过500kb警告
2022-04-25 18:06:22 +08:00
chunkSizeWarningLimit: 4000
2021-04-09 12:54:03 +08:00
},
define: {
2022-03-02 20:47:14 +08:00
__INTLIFY_PROD_DEVTOOLS__: false,
__APP_INFO__: JSON.stringify(__APP_INFO__)
2021-07-07 13:33:47 +08:00
}
2021-08-31 11:50:39 +08:00
};
};