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.
This commit is contained in:
geoffsee
2025-07-02 20:25:58 -04:00
committed by Geoff Seemueller
parent 6cc5e038a7
commit fa5b7466bc
4 changed files with 33 additions and 4 deletions

View File

@@ -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() {