Files
Termix/vite.config.ts
T

119 lines
3.0 KiB
TypeScript
Raw Normal View History

2025-09-12 14:42:00 -05:00
import path from "path";
2025-10-01 15:40:10 -05:00
import fs from "fs";
2025-09-12 14:42:00 -05:00
import tailwindcss from "@tailwindcss/vite";
import { defineConfig } from "vite";
+7
2025-11-05 10:36:16 -06:00
import react from "@vitejs/plugin-react";
2026-05-11 01:23:11 -05:00
import svgr from "vite-plugin-svgr";
2025-08-07 02:20:27 -05:00
2025-10-01 15:40:10 -05:00
const sslCertPath = path.join(process.cwd(), "ssl/termix.crt");
const sslKeyPath = path.join(process.cwd(), "ssl/termix.key");
const hasSSL = fs.existsSync(sslCertPath) && fs.existsSync(sslKeyPath);
const useHTTPS = process.env.VITE_HTTPS === "true" && hasSSL;
2026-05-06 15:12:07 -05:00
const packageJson = JSON.parse(
fs.readFileSync(path.join(process.cwd(), "package.json"), "utf8"),
) as { version?: string };
const manualChunkGroups: Record<string, string[]> = {
"react-vendor": ["react", "react-dom"],
"ui-vendor": [
"@radix-ui/react-dialog",
"@radix-ui/react-dropdown-menu",
"@radix-ui/react-select",
"@radix-ui/react-tabs",
"@radix-ui/react-switch",
"@radix-ui/react-tooltip",
"@radix-ui/react-scroll-area",
"@radix-ui/react-separator",
"lucide-react",
"clsx",
"tailwind-merge",
"class-variance-authority",
],
monaco: ["@monaco-editor/react", "monaco-editor"],
"terminal-vendor": [
"@xterm/addon-clipboard",
"@xterm/addon-fit",
"@xterm/addon-unicode11",
"@xterm/addon-web-links",
"@xterm/xterm",
"react-xtermjs",
],
codemirror: [
"@uiw/react-codemirror",
"@codemirror/view",
"@codemirror/state",
"@codemirror/language",
"@codemirror/commands",
"@codemirror/search",
"@codemirror/autocomplete",
"@codemirror/theme-one-dark",
"@uiw/codemirror-extensions-langs",
"@uiw/codemirror-theme-github",
],
"remote-desktop-vendor": ["guacamole-common-js"],
"graph-vendor": ["cytoscape", "react-cytoscapejs"],
"chart-vendor": ["recharts"],
"file-preview-vendor": [
"react-pdf",
"pdfjs-dist",
"react-photo-view",
"react-h5-audio-player",
"react-markdown",
"react-syntax-highlighter",
"remark-gfm",
],
};
function getManualChunk(id: string): string | undefined {
if (!id.includes("node_modules")) return undefined;
const normalizedId = id.replaceAll("\\", "/");
for (const [chunkName, packages] of Object.entries(manualChunkGroups)) {
if (
packages.some((packageName) =>
normalizedId.includes(`/node_modules/${packageName}/`),
)
) {
return chunkName;
}
}
return undefined;
}
2025-10-01 15:40:10 -05:00
2025-08-07 02:20:27 -05:00
export default defineConfig({
2026-05-11 01:23:11 -05:00
plugins: [react(), tailwindcss(), svgr()],
2026-05-06 15:12:07 -05:00
define: {
"import.meta.env.VITE_APP_VERSION": JSON.stringify(
packageJson.version || "0.0.0",
),
},
2025-08-07 02:20:27 -05:00
resolve: {
alias: {
2026-05-11 01:23:11 -05:00
"@": path.resolve(__dirname, "./src/ui"),
2025-08-07 02:20:27 -05:00
},
},
+4
2026-02-12 22:28:13 -06:00
base: process.env.VITE_BASE_PATH || "./",
2025-10-01 15:40:10 -05:00
build: {
sourcemap: false,
rollupOptions: {
output: {
2026-05-06 15:12:07 -05:00
manualChunks: getManualChunk,
2026-01-24 19:49:42 -06:00
},
},
chunkSizeWarningLimit: 1000,
2025-10-01 15:40:10 -05:00
},
server: {
https: useHTTPS
? {
cert: fs.readFileSync(sslCertPath),
key: fs.readFileSync(sslKeyPath),
}
: false,
port: 5173,
host: "localhost",
},
2025-09-12 14:42:00 -05:00
});