更新依赖项和配置以支持新版本的pnpm,优化PostCSS和Tailwind配置,添加延迟输入功能到EffectsPage,提升用户体验
This commit is contained in:
+34
-12
@@ -4,6 +4,7 @@ import path from "node:path";
|
||||
import { createRequire } from "node:module";
|
||||
import { defineConfig, type Plugin } from "vite";
|
||||
|
||||
const PROJECT_ROOT = import.meta.dirname;
|
||||
const require = createRequire(import.meta.url);
|
||||
const tailwindcss3 = require("tailwindcss3");
|
||||
const autoprefixer = require("autoprefixer");
|
||||
@@ -14,8 +15,8 @@ function legacyIndexRewritePlugin(): Plugin {
|
||||
apply: "serve",
|
||||
configureServer(server) {
|
||||
server.middlewares.use((req, _res, next) => {
|
||||
const url = req.url ?? "";
|
||||
if (url === "/" || url === "/index.html") {
|
||||
const url = (req.url ?? "").split("?")[0];
|
||||
if (url === "/" || url === "/index.html" || url === "/i.modern.html") {
|
||||
req.url = "/i.legacy.html";
|
||||
}
|
||||
next();
|
||||
@@ -24,38 +25,59 @@ function legacyIndexRewritePlugin(): Plugin {
|
||||
};
|
||||
}
|
||||
|
||||
/** 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 */";
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [legacyIndexRewritePlugin(), react(), jsxLocPlugin()],
|
||||
plugins: [legacySkipModernCssPlugin(), legacyIndexRewritePlugin(), react(), jsxLocPlugin()],
|
||||
define: {
|
||||
"import.meta.env.VITE_X9_LEGACY": JSON.stringify("1"),
|
||||
},
|
||||
base: process.env.NODE_ENV === "production" ? "/x9/v2/legacy/" : "/",
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.resolve(import.meta.dirname, "client", "src"),
|
||||
"@shared": path.resolve(import.meta.dirname, "shared"),
|
||||
"@assets": path.resolve(import.meta.dirname, "attached_assets"),
|
||||
"@": path.resolve(PROJECT_ROOT, "client", "src"),
|
||||
"@shared": path.resolve(PROJECT_ROOT, "shared"),
|
||||
"@assets": path.resolve(PROJECT_ROOT, "attached_assets"),
|
||||
},
|
||||
dedupe: ["react", "react-dom"],
|
||||
},
|
||||
envDir: path.resolve(import.meta.dirname),
|
||||
root: path.resolve(import.meta.dirname, "client"),
|
||||
publicDir: path.resolve(import.meta.dirname, "client/public"),
|
||||
envDir: path.resolve(PROJECT_ROOT),
|
||||
root: path.resolve(PROJECT_ROOT, "client"),
|
||||
publicDir: path.resolve(PROJECT_ROOT, "client/public"),
|
||||
css: {
|
||||
transformer: "postcss",
|
||||
postcss: {
|
||||
plugins: [tailwindcss3({ config: "./tailwind.legacy.config.cjs" }), autoprefixer()],
|
||||
plugins: [
|
||||
tailwindcss3({ config: path.join(PROJECT_ROOT, "tailwind.legacy.config.cjs") }),
|
||||
autoprefixer(),
|
||||
],
|
||||
},
|
||||
},
|
||||
build: {
|
||||
target: ["chrome91", "edge91"],
|
||||
cssTarget: "chrome91",
|
||||
outDir: path.resolve(import.meta.dirname, "dist/legacy"),
|
||||
outDir: path.resolve(PROJECT_ROOT, "dist/legacy"),
|
||||
emptyOutDir: true,
|
||||
minify: "terser",
|
||||
rollupOptions: {
|
||||
input: {
|
||||
i: path.resolve(import.meta.dirname, "client", "i.legacy.html"),
|
||||
i: path.resolve(PROJECT_ROOT, "client", "i.legacy.html"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user