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