refactor(web): migrate from Vike+React to SvelteKit

- Replace Vike+React with SvelteKit for simpler SSR and routing
- Update WASM build output paths from public/ to static/
- Add wasm-opt integration for WASM size optimization
- Streamline tooling: remove ESLint, Prettier configs (use defaults)
- Move build.rs to pacman-server/ (frontend no longer needs it)
This commit is contained in:
2025-12-30 02:15:42 -06:00
parent 1c333c83fc
commit a636870661
52 changed files with 2291 additions and 2039 deletions
+48 -2
View File
@@ -67,7 +67,7 @@ async function build(release: boolean, env: Record<string, string> | null) {
const buildType = release ? "release" : "debug";
const outputFolder = resolve(`target/wasm32-unknown-emscripten/${buildType}`);
const dist = resolve("web/public");
const dist = resolve("web/static");
// The files to copy into 'dist'
const files = [
@@ -98,7 +98,7 @@ async function build(release: boolean, env: Record<string, string> | null) {
);
// Copy the files to the dist folder
logger.debug("Copying Emscripten build artifacts into web/public");
logger.debug("Copying Emscripten build artifacts into web/static");
await Promise.all(
files.map(async ({ optional, src, dest }) => {
match({ optional, exists: await fs.exists(src) })
@@ -120,9 +120,55 @@ async function build(release: boolean, env: Record<string, string> | null) {
})
);
// Optimize WASM binary for size using wasm-opt (if available)
const wasmPath = join(dist, "pacman.wasm");
await optimizeWasm(wasmPath);
logger.info("Emscripten build complete");
}
/**
* Optimize a WASM binary using wasm-opt (from binaryen).
* Silently skips if wasm-opt is not installed.
*
* @param wasmPath - Path to the WASM file to optimize in-place.
*/
async function optimizeWasm(wasmPath: string): Promise<void> {
// Check if wasm-opt is available
const whichCmd = os.type === "windows" ? "where" : "which";
const checkResult = await $`${whichCmd} wasm-opt`.quiet().nothrow();
if (checkResult.exitCode !== 0) {
logger.debug(
"wasm-opt not found, skipping WASM optimization (install binaryen to enable)"
);
return;
}
const originalSize = (await fs.stat(wasmPath)).size;
logger.debug(`Optimizing WASM binary (original: ${formatBytes(originalSize)})`);
const result = await $`wasm-opt -Oz --strip-debug ${wasmPath} -o ${wasmPath}`.quiet().nothrow();
if (result.exitCode !== 0) {
logger.warn(`wasm-opt failed: ${result.stderr.toString()}`);
return;
}
const optimizedSize = (await fs.stat(wasmPath)).size;
const reduction = ((originalSize - optimizedSize) / originalSize) * 100;
logger.info(
`WASM optimized: ${formatBytes(originalSize)} -> ${formatBytes(optimizedSize)} (${reduction.toFixed(1)}% reduction)`
);
}
/**
* Format bytes as a human-readable string.
*/
function formatBytes(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KiB`;
return `${(bytes / (1024 * 1024)).toFixed(2)} MiB`;
}
// (Tailwind-related code removed; this script is now focused solely on the Emscripten build)
/**