Files
lolympus-tournament-support/apps/web/vite.config.ts
dahyeon 9d7c888b0a fix: migrate deprecated APIs and patch vulnerable dependencies
Use current Mongoose, NATS, React, and ESLint APIs. Upgrade Vite and other affected dependencies, restrict the compatibility plugin to resolved module IDs, and keep qs unchanged.
2026-11-11 22:41:42 +09:00

75 lines
2.3 KiB
TypeScript

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import { createRequire } from "node:module";
import fs from "node:fs";
import path from "node:path";
const ES_TOOLKIT_COMPAT_RE = /^es-toolkit\/compat\/[A-Za-z0-9_$]+$/;
const VIRTUAL_ES_TOOLKIT_COMPAT_PREFIX = "\0es-toolkit-compat-esm:";
// Share resolved modules between the app and dependency optimizer plugins.
const resolvedCompatModules = new Map<
string,
{ exportName: string; esmPath: string }
>();
function esToolkitCompatEsm() {
return {
name: "es-toolkit-compat-esm",
enforce: "pre" as const,
resolveId(source: string, importer?: string) {
if (!importer || !ES_TOOLKIT_COMPAT_RE.test(source)) {
return null;
}
const requireFromImporter = createRequire(importer);
const wrapperPath = requireFromImporter.resolve(source);
const wrapperSource = fs.readFileSync(wrapperPath, "utf8");
const wrapperMatch = wrapperSource.match(
/require\(['"](\.\.\/dist\/compat\/[^'"]+)\.js['"]\)\.([A-Za-z0-9_$]+)/,
);
if (!wrapperMatch) {
return null;
}
const [, esmPathWithoutExtension, exportName] = wrapperMatch;
const esmPath = path.resolve(
path.dirname(wrapperPath),
`${esmPathWithoutExtension}.mjs`,
);
const id = `${VIRTUAL_ES_TOOLKIT_COMPAT_PREFIX}${encodeURIComponent(
exportName,
)}:${encodeURIComponent(esmPath)}`;
resolvedCompatModules.set(id, { exportName, esmPath });
return id;
},
load(id: string) {
// A dev-server request can supply a virtual ID directly. Only load IDs
// previously produced by resolving an installed es-toolkit module.
const module = resolvedCompatModules.get(id);
if (!module) return null;
const { exportName, esmPath } = module;
return `export { ${exportName} as default, ${exportName} } from ${JSON.stringify(
esmPath,
)};`;
},
};
}
// https://vite.dev/config/
export default defineConfig({
plugins: [esToolkitCompatEsm(), react(), tailwindcss()],
optimizeDeps: {
rolldownOptions: {
plugins: [esToolkitCompatEsm()],
},
},
server: {
host: "0.0.0.0",
allowedHosts: ["126.dahyeon.us"],
},
});