Files
gitlab-instance-0a899031_fi…/frontend/vite.config.ts
2025-09-29 13:15:15 +08:00

95 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import path from "node:path";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite";
import legacy from "@vitejs/plugin-legacy";
import { compression } from "vite-plugin-compression2";
const plugins = [
vue(),
VueI18nPlugin({
include: [path.resolve(__dirname, "./src/i18n/**/*.json")],
}),
legacy({
// defaults already drop IE support
targets: ["defaults"],
}),
compression({ include: /\.js$/i, deleteOriginalAssets: true }),
];
const resolve = {
alias: {
// vue: "@vue/compat",
"@/": `${path.resolve(__dirname, "src")}/`,
},
};
// https://vitejs.dev/config/
export default defineConfig(({ command }) => {
if (command === "serve") {
return {
plugins,
resolve,
server: {
// proxy: {
// "/api/command": {
// target: "ws://127.0.0.1:8080",
// ws: true,
// },
// "/api": "http://127.0.0.1:8080",
// },
proxy: {
// Zero3 后端 WebSocket如果你有 ws 接口)
"/api/command": {
target: `ws://${location.protocol}//${location.hostname}:8081`,
// target: "ws://live.local:8081",
ws: true,
},
// Zero3 后端 HTTP
"/api": `${location.protocol}//${location.hostname}:8081`,
// "/api": "http://live.local:8081",
},
},
};
} else {
// command === 'build'
return {
plugins,
resolve,
base: "",
build: {
rollupOptions: {
input: {
index: path.resolve(__dirname, "./public/index.html"),
},
output: {
manualChunks: (id) => {
// bundle dayjs files in a single chunk
// this avoids having small files for each locale
if (id.includes("dayjs/")) {
return "dayjs";
// bundle i18n in a separate chunk
} else if (id.includes("i18n/")) {
return "i18n";
}
},
},
},
},
experimental: {
renderBuiltUrl(filename, { hostType }) {
if (hostType === "js") {
return { runtime: `window.__prependStaticUrl("${filename}")` };
} else if (hostType === "html") {
return `[{[ .StaticURL ]}]/${filename}`;
} else {
return { relative: true };
}
},
},
};
}
});