71 lines
1.8 KiB
TypeScript
71 lines
1.8 KiB
TypeScript
import { fileURLToPath, URL } from "node:url";
|
|
|
|
import vue from "@vitejs/plugin-vue";
|
|
import { defineConfig, loadEnv, type PluginOption } from "vite";
|
|
import { compression } from "vite-plugin-compression2";
|
|
|
|
const r = (path: string) => fileURLToPath(new URL(path, import.meta.url));
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
const env = loadEnv(mode, ".", "");
|
|
const isProd = mode === "production";
|
|
const plugins: PluginOption[] = [vue()];
|
|
|
|
if (isProd) {
|
|
plugins.push(
|
|
compression({
|
|
algorithms: ["gzip", "brotliCompress"],
|
|
threshold: 1024,
|
|
}),
|
|
);
|
|
}
|
|
|
|
return {
|
|
plugins,
|
|
resolve: {
|
|
alias: {
|
|
"@": r("./src"),
|
|
},
|
|
},
|
|
server: {
|
|
host: "0.0.0.0",
|
|
port: 5174,
|
|
proxy: {
|
|
"/api": {
|
|
target: env.VITE_OPS_API_PROXY_TARGET || "http://localhost:8090",
|
|
changeOrigin: true,
|
|
},
|
|
},
|
|
},
|
|
esbuild: isProd ? { drop: ["console", "debugger"] } : undefined,
|
|
build: {
|
|
target: "es2022",
|
|
sourcemap: "hidden",
|
|
cssCodeSplit: true,
|
|
reportCompressedSize: false,
|
|
rollupOptions: {
|
|
output: {
|
|
entryFileNames: "assets/js/[name]-[hash].js",
|
|
chunkFileNames: "assets/js/[name]-[hash].js",
|
|
assetFileNames: "assets/[name]-[hash][extname]",
|
|
manualChunks(id) {
|
|
if (!id.includes("node_modules")) return undefined;
|
|
if (id.includes("/ant-design-vue/") || id.includes("/@ant-design/")) {
|
|
return "antd";
|
|
}
|
|
if (
|
|
id.includes("/vue/") ||
|
|
id.includes("/@vue/") ||
|
|
id.includes("/vue-router/") ||
|
|
id.includes("/pinia/")
|
|
) {
|
|
return "vue-vendor";
|
|
}
|
|
return "vendor";
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
});
|