2026-06-02 19:55:09 +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";
|
|
|
|
|
|
2026-06-09 14:24:30 +08:00
|
|
|
const PROJECT_ROOT = import.meta.dirname;
|
2026-06-02 19:55:09 +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) => {
|
2026-06-09 14:24:30 +08:00
|
|
|
const url = (req.url ?? "").split("?")[0];
|
|
|
|
|
if (url === "/" || url === "/index.html" || url === "/i.modern.html") {
|
2026-06-02 19:55:09 +08:00
|
|
|
req.url = "/i.legacy.html";
|
|
|
|
|
}
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-09 14:24:30 +08:00
|
|
|
/** 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 */";
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-02 19:55:09 +08:00
|
|
|
export default defineConfig({
|
2026-06-09 14:24:30 +08:00
|
|
|
plugins: [legacySkipModernCssPlugin(), legacyIndexRewritePlugin(), react(), jsxLocPlugin()],
|
|
|
|
|
define: {
|
|
|
|
|
"import.meta.env.VITE_X8_LEGACY": JSON.stringify("1"),
|
|
|
|
|
},
|
2026-06-02 19:55:09 +08:00
|
|
|
base: process.env.NODE_ENV === "production" ? "/x8/v2/legacy/" : "/",
|
|
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
2026-06-09 14:24:30 +08:00
|
|
|
"@": path.resolve(PROJECT_ROOT, "client", "src"),
|
|
|
|
|
"@shared": path.resolve(PROJECT_ROOT, "shared"),
|
|
|
|
|
"@assets": path.resolve(PROJECT_ROOT, "attached_assets"),
|
2026-06-02 19:55:09 +08:00
|
|
|
},
|
|
|
|
|
dedupe: ["react", "react-dom"],
|
|
|
|
|
},
|
2026-06-09 14:24:30 +08:00
|
|
|
envDir: path.resolve(PROJECT_ROOT),
|
|
|
|
|
root: path.resolve(PROJECT_ROOT, "client"),
|
|
|
|
|
publicDir: path.resolve(PROJECT_ROOT, "client/public"),
|
2026-06-02 19:55:09 +08:00
|
|
|
css: {
|
|
|
|
|
transformer: "postcss",
|
|
|
|
|
postcss: {
|
2026-06-09 14:24:30 +08:00
|
|
|
plugins: [
|
|
|
|
|
tailwindcss3({ config: path.join(PROJECT_ROOT, "tailwind.legacy.config.cjs") }),
|
|
|
|
|
autoprefixer(),
|
|
|
|
|
],
|
2026-06-02 19:55:09 +08:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
build: {
|
|
|
|
|
target: ["chrome91", "edge91"],
|
|
|
|
|
cssTarget: "chrome91",
|
2026-06-09 14:24:30 +08:00
|
|
|
outDir: path.resolve(PROJECT_ROOT, "dist/legacy"),
|
2026-06-02 19:55:09 +08:00
|
|
|
emptyOutDir: true,
|
|
|
|
|
minify: "terser",
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
input: {
|
2026-06-09 14:24:30 +08:00
|
|
|
i: path.resolve(PROJECT_ROOT, "client", "i.legacy.html"),
|
2026-06-02 19:55:09 +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"),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|