mirror of
https://github.com/Xevion/smart-rgb.git
synced 2025-12-10 06:08:41 -06:00
Update source files
This commit is contained in:
130
frontend/vite.config.ts
Normal file
130
frontend/vite.config.ts
Normal file
@@ -0,0 +1,130 @@
|
||||
import { defineConfig, HmrContext } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import vike from "vike/plugin";
|
||||
import { resolve } from "path";
|
||||
import { readFileSync, existsSync } from "fs";
|
||||
import { execSync } from "child_process";
|
||||
import { imagetools } from "vite-imagetools";
|
||||
|
||||
const host = process.env.TAURI_DEV_HOST;
|
||||
|
||||
// Read version from workspace Cargo.toml
|
||||
function getVersionFromCargoToml(): string {
|
||||
const cargoToml = readFileSync(resolve(__dirname, "../Cargo.toml"), "utf-8");
|
||||
const versionMatch = cargoToml.match(/^\[workspace\.package\][\s\S]*?^version\s*=\s*"(.+?)"$/m);
|
||||
if (!versionMatch) {
|
||||
throw new Error("Failed to find version in workspace Cargo.toml");
|
||||
}
|
||||
return versionMatch[1];
|
||||
}
|
||||
|
||||
// Read git commit from .source-commit file or git command
|
||||
function getGitCommit(): string {
|
||||
const sourceCommitPath = resolve(__dirname, "../.source-commit");
|
||||
if (existsSync(sourceCommitPath)) {
|
||||
return readFileSync(sourceCommitPath, "utf-8").trim();
|
||||
}
|
||||
|
||||
// Fallback to git command for local development
|
||||
try {
|
||||
return execSync("git rev-parse HEAD", { encoding: "utf-8", cwd: resolve(__dirname, "..") }).trim();
|
||||
} catch {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
// Get current build time in UTC (ISO 8601 format)
|
||||
function getBuildTime(): string {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
|
||||
const fullReloadAlways = {
|
||||
name: "full-reload-always",
|
||||
handleHotUpdate(context: HmrContext): void {
|
||||
context.server.ws.send({ type: "full-reload" });
|
||||
},
|
||||
};
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig(({ mode }) => ({
|
||||
base: process.env.GITHUB_PAGES === "true" ? "/borde.rs/" : "/",
|
||||
css: {
|
||||
transformer: "lightningcss",
|
||||
},
|
||||
plugins: [vike(), react(), imagetools(), fullReloadAlways],
|
||||
|
||||
define: {
|
||||
__DESKTOP__: JSON.stringify(mode !== "browser"),
|
||||
__APP_VERSION__: JSON.stringify(getVersionFromCargoToml()),
|
||||
__GIT_COMMIT__: JSON.stringify(getGitCommit()),
|
||||
__BUILD_TIME__: JSON.stringify(getBuildTime()),
|
||||
},
|
||||
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": resolve(__dirname, "src"),
|
||||
"@wasm": resolve(__dirname, "pkg"),
|
||||
},
|
||||
},
|
||||
|
||||
build: {
|
||||
outDir: mode === "browser" ? "dist/browser" : "dist",
|
||||
cssMinify: "lightningcss",
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks: (id) => {
|
||||
// console.log(id);
|
||||
if (id.includes("node_modules")) {
|
||||
// React core - always needed
|
||||
if (id.includes("react") || id.includes("react-dom")) {
|
||||
return "vendor-react";
|
||||
}
|
||||
|
||||
// PixiJS - large rendering library
|
||||
if (id.includes("pixi")) {
|
||||
return "vendor-pixi";
|
||||
}
|
||||
|
||||
// UI libraries - icons, scrollbars, animations
|
||||
if (id.includes("radix-ui") || id.includes("lucide-react") || id.includes("overlayscrollbars") || id.includes("motion")) {
|
||||
return "vendor-ui";
|
||||
}
|
||||
|
||||
return "vendor-other";
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
|
||||
//
|
||||
// 1. prevent Vite from obscuring rust errors
|
||||
clearScreen: false,
|
||||
// 2. tauri expects a fixed port, fail if that port is not available
|
||||
server: {
|
||||
// Browser mode uses port 1421, desktop mode uses port 1420
|
||||
port: mode === "browser" ? 1421 : 1420,
|
||||
strictPort: true,
|
||||
host: host || false,
|
||||
hmr: host
|
||||
? {
|
||||
protocol: "ws",
|
||||
host,
|
||||
port: mode === "browser" ? 1422 : 1421,
|
||||
}
|
||||
: undefined,
|
||||
watch: {
|
||||
// 3. tell Vite to ignore watching `src-tauri`
|
||||
ignored: ["**/crates/borders-desktop/**"],
|
||||
},
|
||||
// Add headers for SharedArrayBuffer support in browser mode
|
||||
headers:
|
||||
mode === "browser"
|
||||
? {
|
||||
"Cross-Origin-Opener-Policy": "same-origin",
|
||||
"Cross-Origin-Embedder-Policy": "require-corp",
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user