-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
90 lines (85 loc) · 2.44 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import dayjs from "dayjs";
import { resolve } from "path";
import pkg from "./package.json";
import { warpperEnv } from "./build";
import { getPluginsList } from "./build/plugins";
import { include, exclude } from "./build/optimize";
import { UserConfigExport, ConfigEnv, loadEnv } from "vite";
/** 当前执行node命令时文件夹的地址(工作目录) */
const root: string = process.cwd();
/** 路径查找 */
const pathResolve = (dir: string): string => {
return resolve(__dirname, ".", dir);
};
/** 设置别名 */
const alias: Record<string, string> = {
"@": pathResolve("src"),
"@build": pathResolve("build")
};
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 => {
const {
VITE_CDN,
VITE_PORT,
VITE_COMPRESSION,
VITE_PUBLIC_PATH,
VITE_API_BASE_URL,
VITE_BUILD_TYPE,
} = warpperEnv(loadEnv(mode, root));
return {
base: VITE_PUBLIC_PATH,
root,
resolve: { alias },
server: {
https: false,
port: VITE_PORT,
host: "0.0.0.0",
proxy: {
"/management": {
target: VITE_API_BASE_URL,
rewrite: path => path.replace(/^\/management/, ""),
changeOrigin: true,
configure: (proxy, _) => {
proxy.on("proxyRes", (_, req, _r) => {
console.log(req.url);
});
},
headers: {
Origin: VITE_API_BASE_URL,
Referer: VITE_API_BASE_URL
}
},
}
},
plugins: getPluginsList(command, VITE_CDN, VITE_COMPRESSION),
optimizeDeps: {
include,
exclude
},
build: {
sourcemap: false,
// 消除打包大小超过500kb警告
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]"
}
},
outDir: `dist${VITE_BUILD_TYPE === 'production' ? '/dpgames-management-back-stage' : ''}`,
},
define: {
__INTLIFY_PROD_DEVTOOLS__: false,
__APP_INFO__: JSON.stringify(__APP_INFO__)
}
};
};