pure-admin-thin/vite.config.ts
Truong Nguyen f0c4f1f39e update
2024-07-10 18:08:06 +07:00

63 lines
1.9 KiB
TypeScript

import { getPluginsList } from "./build/plugins";
import { include, exclude } from "./build/optimize";
import { type UserConfigExport, type ConfigEnv, loadEnv } from "vite";
import {
root,
alias,
wrapperEnv,
pathResolve,
__APP_INFO__
} from "./build/utils";
export default ({ mode }: ConfigEnv): UserConfigExport => {
const { VITE_CDN, VITE_PORT, VITE_COMPRESSION, VITE_PUBLIC_PATH } =
wrapperEnv(loadEnv(mode, root));
return {
base: VITE_PUBLIC_PATH,
root,
resolve: {
alias
},
// Server-side rendering
server: {
// Port number
port: VITE_PORT,
host: "0.0.0.0",
// Local cross-origin proxy https://cn.vitejs.dev/config/server-options.html#server-proxy
proxy: {},
// Preheat files to pre-transform and cache results, reducing initial page load time during startup and preventing transformation waterfall
warmup: {
clientFiles: ["./index.html", "./src/{views,components}/*"]
}
},
plugins: getPluginsList(VITE_CDN, VITE_COMPRESSION),
// https://cn.vitejs.dev/config/dep-optimization-options.html#dep-optimization-options
optimizeDeps: {
include,
exclude
},
build: {
// https://cn.vitejs.dev/guide/build.html#browser-compatibility
target: "es2015",
sourcemap: false,
// Eliminate package size warning over 500kb
chunkSizeWarningLimit: 4000,
rollupOptions: {
input: {
index: pathResolve("./index.html", import.meta.url)
},
// Static resource classification packaging
output: {
chunkFileNames: "static/js/[name]-[hash].js",
entryFileNames: "static/js/[name]-[hash].js",
assetFileNames: "static/[ext]/[name]-[hash].[ext]"
}
}
},
define: {
__INTLIFY_PROD_DEVTOOLS__: false,
__APP_INFO__: JSON.stringify(__APP_INFO__)
}
};
};