Files
controller-v2/vite.legacy.config.ts
T

119 lines
3.4 KiB
TypeScript
Raw Normal View History

2026-06-03 15:42:58 +08:00
import { jsxLocPlugin } from "@builder.io/vite-plugin-jsx-loc";
import react from "@vitejs/plugin-react";
import path from "node:path";
import { createRequire } from "node:module";
import { defineConfig, type Plugin } from "vite";
const PROJECT_ROOT = import.meta.dirname;
2026-06-03 15:42:58 +08:00
const require = createRequire(import.meta.url);
const tailwindcss3 = require("tailwindcss3");
const autoprefixer = require("autoprefixer");
function legacyIndexRewritePlugin(): Plugin {
return {
name: "legacy-index-rewrite",
apply: "serve",
configureServer(server) {
server.middlewares.use((req, _res, next) => {
const url = (req.url ?? "").split("?")[0];
if (url === "/" || url === "/index.html" || url === "/i.modern.html") {
2026-06-03 15:42:58 +08:00
req.url = "/i.legacy.html";
}
next();
});
},
};
}
/** Dev MPA may discover modern CSS — stub them so Tailwind v3 postcss does not choke. */
function legacySkipModernCssPlugin(): Plugin {
return {
name: "legacy-skip-modern-css",
enforce: "pre",
apply: "serve",
load(id) {
const norm = id.replace(/\\/g, "/");
if (norm.endsWith("/client/src/index.css")) {
return "/* legacy dev: skip modern index.css */";
}
if (/node_modules\/tailwindcss\/index\.css/.test(norm)) {
return "/* legacy dev: skip tailwind v4 */";
}
},
};
}
/* ── Deploy base path ── */
const DEPLOY_ENV = process.env.DEPLOY_ENV || "production";
const isProd = process.env.NODE_ENV === "production";
const deployBase = isProd
2026-07-17 17:16:26 +08:00
? (DEPLOY_ENV === "test" ? "/b9/test/legacy/" : "/b9/v2/legacy/")
: "/";
2026-06-03 15:42:58 +08:00
export default defineConfig({
plugins: [legacySkipModernCssPlugin(), legacyIndexRewritePlugin(), react(), jsxLocPlugin()],
2026-06-03 15:42:58 +08:00
define: {
"import.meta.env.VITE_X9_LEGACY": JSON.stringify("1"),
},
base: deployBase,
2026-06-03 15:42:58 +08:00
resolve: {
alias: {
"@": path.resolve(PROJECT_ROOT, "client", "src"),
"@assets": path.resolve(PROJECT_ROOT, "attached_assets"),
2026-06-03 15:42:58 +08:00
},
dedupe: ["react", "react-dom"],
},
envDir: path.resolve(PROJECT_ROOT),
root: path.resolve(PROJECT_ROOT, "client"),
publicDir: path.resolve(PROJECT_ROOT, "client/public"),
2026-06-03 15:42:58 +08:00
css: {
transformer: "postcss",
postcss: {
plugins: [
tailwindcss3({ config: path.join(PROJECT_ROOT, "tailwind.legacy.config.cjs") }),
autoprefixer(),
],
2026-06-03 15:42:58 +08:00
},
},
build: {
target: ["chrome91", "edge91"],
cssTarget: "chrome91",
outDir: path.resolve(PROJECT_ROOT, "dist/legacy"),
2026-06-03 15:42:58 +08:00
emptyOutDir: true,
minify: "terser",
rollupOptions: {
input: {
i: path.resolve(PROJECT_ROOT, "client", "i.legacy.html"),
2026-06-03 15:42:58 +08:00
},
2026-06-12 15:53:05 +08:00
output: {
manualChunks(id) {
if (!id.includes("node_modules")) return;
// Match modern build: echarts is lazy-loaded on EQ/Effects pages.
if (
id.includes("/echarts/") ||
id.includes("/zrender/") ||
id.includes("\\echarts\\") ||
id.includes("\\zrender\\")
) {
return "echarts-vendor";
}
},
},
2026-06-03 15:42:58 +08:00
},
2026-06-12 15:53:05 +08:00
// streamdown pulls @shikijs/langs + mermaid; both lazy-loaded with AIPage.
chunkSizeWarningLimit: 15000,
2026-06-03 15:42:58 +08:00
},
server: {
port: 5173,
strictPort: false,
host: true,
proxy: {
"/luxsin-audio-api": {
target: "https://api.luxsin.com.cn",
changeOrigin: true,
rewrite: (p) => p.replace(/^\/luxsin-audio-api/, "/audio"),
},
},
},
});