vue-pure-admin2/vite.config.ts

63 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-02-05 17:34:01 +08:00
import { getPluginsList } from "./build/plugins";
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 => {
const { VITE_CDN, VITE_PORT, VITE_COMPRESSION, VITE_PUBLIC_PATH } =
2024-04-26 10:59:48 +08:00
wrapperEnv(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: {
2021-12-04 01:16:50 +08:00
// 端口号
port: VITE_PORT,
2021-07-22 11:33:45 +08:00
host: "0.0.0.0",
// 本地跨域代理 https://cn.vitejs.dev/config/server-options.html#server-proxy
proxy: {},
// 预热文件以提前转换和缓存结果,降低启动期间的初始页面加载时长并防止转换瀑布
warmup: {
clientFiles: ["./index.html", "./src/{views,components}/*"]
}
},
2023-11-16 22:01:20 +08:00
plugins: getPluginsList(VITE_CDN, VITE_COMPRESSION),
// 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,
exclude
2021-04-21 23:20:14 +08:00
},
build: {
// https://cn.vitejs.dev/guide/build.html#browser-compatibility
target: "es2015",
2021-08-27 01:33:57 +08:00
sourcemap: false,
// 消除打包大小超过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
};
};