From fa5b7466bcf1f0908feecd8fa5e1bf8e6518fcfe Mon Sep 17 00:00:00 2001 From: geoffsee <> Date: Wed, 2 Jul 2025 20:25:58 -0400 Subject: [PATCH] Optimize WASM handling and integrate service worker caching. Removed unused pointer events in BevyScene, updated Vite config with Workbox for service worker caching, and adjusted file paths in generate-bevy-bundle.js. Added WASM size optimization to ensure smaller and efficient builds, skipping optimization for files below 30MB. --- crates/yachtpit | 2 +- .../client/scripts/generate-bevy-bundle.js | 26 +++++++++++++++++-- .../landing-component/BevyScene.tsx | 1 - packages/client/vite.config.ts | 8 ++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/crates/yachtpit b/crates/yachtpit index 66b8a85..1abe004 160000 --- a/crates/yachtpit +++ b/crates/yachtpit @@ -1 +1 @@ -Subproject commit 66b8a855b513c11511cbc3b59b96bca76e34c3a5 +Subproject commit 1abe0047fc20aafe6c8b4393cd4ebb98450c8d2f diff --git a/packages/client/scripts/generate-bevy-bundle.js b/packages/client/scripts/generate-bevy-bundle.js index 414693f..a830085 100644 --- a/packages/client/scripts/generate-bevy-bundle.js +++ b/packages/client/scripts/generate-bevy-bundle.js @@ -7,6 +7,7 @@ import { renameSync, rmSync, cpSync, + statSync, } from 'node:fs'; import { resolve, dirname, join, basename } from 'node:path'; @@ -49,7 +50,7 @@ function bundleCrate() { } // Build the yachtpit project - const buildCwd = resolve(repoRoot, 'crates/yachtpit'); + const buildCwd = resolve(repoRoot, 'crates/yachtpit/crates/yachtpit'); logger.info(`🔨 Building in directory: ${buildCwd}`); try { @@ -63,7 +64,7 @@ function bundleCrate() { } // ───────────── Copy assets to public directory ────────────────────────── - const yachtpitDistDir = join(yachtpitPath, 'dist'); + const yachtpitDistDir = join(buildCwd, 'dist'); logger.info(`📋 Copying assets to public directory...`); @@ -152,6 +153,27 @@ function bundleCrate() { } else { logger.info(`⚠️ ${indexHtml} not found – skipping HTML processing.`); } + optimizeWasmSize(); +} + +function optimizeWasmSize() { + logger.info('🔨 Checking WASM size...'); + + const wasmPath = resolve(publicDir, 'yachtpit_bg.wasm'); + const fileSize = statSync(wasmPath).size; + const sizeInMb = fileSize / (1024 * 1024); + + if (sizeInMb > 30) { + logger.info(`WASM size is ${sizeInMb.toFixed(2)}MB, optimizing...`); + execSync(`wasm-opt -Oz -o ${wasmPath} ${wasmPath}`, { + encoding: 'utf-8', + }); + logger.info(`✅ WASM size optimized`); + } else { + logger.info( + `⏩ Skipping WASM optimization, size (${sizeInMb.toFixed(2)}MB) is under 30MB threshold`, + ); + } } function cleanup() { diff --git a/packages/client/src/components/landing-component/BevyScene.tsx b/packages/client/src/components/landing-component/BevyScene.tsx index de5143f..d94d37f 100644 --- a/packages/client/src/components/landing-component/BevyScene.tsx +++ b/packages/client/src/components/landing-component/BevyScene.tsx @@ -32,7 +32,6 @@ const BevySceneInner: React.FC = ({ position: 'absolute' as const, inset: 0, zIndex: 0, - pointerEvents: 'none' as const, opacity: visible ? Math.min(Math.max(intensity, 0), 1) : 0, filter: glow ? 'blur(1px)' : 'none', transition: `opacity ${speed}s ease-in-out`, diff --git a/packages/client/vite.config.ts b/packages/client/vite.config.ts index a76f242..dffaee6 100644 --- a/packages/client/vite.config.ts +++ b/packages/client/vite.config.ts @@ -114,6 +114,14 @@ export default defineConfig(({ command }) => { }) */ ], + workbox: { + globPatterns: ['**/*.{js,css,html,ico,png,svg,wasm}'], + navigateFallbackDenylist: [/^\/api\//], + maximumFileSizeToCacheInBytes: 25000000, + cacheId: buildId, + cleanupOutdatedCaches: true, + clientsClaim: true, + }, server: { port: 3000, proxy: {