Files
Termix/vite.config.ts
T

126 lines
3.4 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";
2026-10-01 16:20:16 -05:00
import { termixPluginHost } from "./scripts/vite-plugin-termix-plugins.mjs";
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-10-01 16:20:16 -05:00
// Everything rides the main backend on 30001, plugins included (under
// /plugin-api and /plugin-ws).
const apiProxyPorts = [30001];
+5
2026-08-19 14:12:06 -05:00
const apiProxy = Object.fromEntries(
apiProxyPorts.map((port) => [
`/__termix_api/${port}`,
{
target: `http://127.0.0.1:${port}`,
changeOrigin: true,
ws: true,
rewrite: (requestPath: string) =>
requestPath.replace(new RegExp(`^/__termix_api/${port}`), ""),
},
]),
);
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",
],
codemirror: [
"@uiw/react-codemirror",
"@codemirror/view",
"@codemirror/state",
"@codemirror/language",
"@codemirror/theme-one-dark",
],
};
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
2026-10-01 16:20:16 -05:00
// The SDK's browser entries resolve to source, so the shell and workspace
// plugins share one instance in dev and nobody waits on a stale SDK build.
const sdkFrontendEntry = path.resolve(
__dirname,
"./packages/plugin-sdk/src/frontend.ts",
);
const sdkUiEntry = path.resolve(__dirname, "./src/ui/plugin-host/sdk-ui.ts");
2025-08-07 02:20:27 -05:00
export default defineConfig({
2026-10-01 16:20:16 -05:00
plugins: [
react(),
tailwindcss(),
svgr(),
termixPluginHost({ repoRoot: __dirname, sdkFrontendEntry, sdkUiEntry }),
],
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-10-10 14:58:27 -05:00
"@termix-ssh/plugin-sdk/frontend": sdkFrontendEntry,
"@termix-ssh/plugin-sdk/ui": sdkUiEntry,
2026-05-28 22:29:20 -05:00
"@/types": path.resolve(__dirname, "./src/types"),
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",
+5
2026-08-19 14:12:06 -05:00
proxy: apiProxy,
2025-10-01 15:40:10 -05:00
},
2025-09-12 14:42:00 -05:00
});