mirror of
https://github.com/Xevion/Pac-Man.git
synced 2026-01-31 00:24:59 -06:00
feat(web): add cache busting with version-based asset loading
- Inject git hash via Vite plugin for cache-busting WASM/JS assets - Enable Emscripten assertions for better runtime error messages - Log Emscripten runtime init for debugging filesystem readiness - Expand dockerignore to exclude web build artifacts
This commit is contained in:
+49
-2
@@ -1,11 +1,58 @@
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import vike from "vike/plugin";
|
||||
import { defineConfig } from "vite";
|
||||
import { defineConfig, Plugin } from "vite";
|
||||
import path from "path";
|
||||
import { execSync } from "child_process";
|
||||
|
||||
/**
|
||||
* Vite plugin that injects the Pacman version hash at build time.
|
||||
* Uses git commit hash in production/dev, falls back to timestamp if git unavailable.
|
||||
*/
|
||||
function pacmanVersionPlugin(): Plugin {
|
||||
let version: string;
|
||||
|
||||
function getVersion(mode: string): string {
|
||||
// Development mode uses fixed "dev" string
|
||||
if (mode === "development") {
|
||||
return "dev";
|
||||
}
|
||||
|
||||
// Try to get git commit hash
|
||||
try {
|
||||
const hash = execSync("git rev-parse --short HEAD", {
|
||||
encoding: "utf8",
|
||||
stdio: ["pipe", "pipe", "pipe"],
|
||||
}).trim();
|
||||
|
||||
if (hash) {
|
||||
return hash;
|
||||
}
|
||||
} catch {
|
||||
// Git not available or command failed
|
||||
}
|
||||
|
||||
// Fallback to timestamp
|
||||
return Date.now().toString(36);
|
||||
}
|
||||
|
||||
return {
|
||||
name: "pacman-version",
|
||||
config(_, { mode }) {
|
||||
version = getVersion(mode);
|
||||
console.log(`[pacman-version] Using version: ${version}`);
|
||||
|
||||
return {
|
||||
define: {
|
||||
"import.meta.env.VITE_PACMAN_VERSION": JSON.stringify(version),
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vike(), react(), tailwindcss()],
|
||||
plugins: [pacmanVersionPlugin(), vike(), react(), tailwindcss()],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.resolve(__dirname, "."),
|
||||
|
||||
Reference in New Issue
Block a user