mirror of
https://github.com/geoffsee/open-gsio.git
synced 2025-09-08 22:56:46 +00:00
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:
Submodule crates/yachtpit updated: 66b8a855b5...1abe0047fc
@@ -7,6 +7,7 @@ import {
|
|||||||
renameSync,
|
renameSync,
|
||||||
rmSync,
|
rmSync,
|
||||||
cpSync,
|
cpSync,
|
||||||
|
statSync,
|
||||||
} from 'node:fs';
|
} from 'node:fs';
|
||||||
import { resolve, dirname, join, basename } from 'node:path';
|
import { resolve, dirname, join, basename } from 'node:path';
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ function bundleCrate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build the yachtpit project
|
// Build the yachtpit project
|
||||||
const buildCwd = resolve(repoRoot, 'crates/yachtpit');
|
const buildCwd = resolve(repoRoot, 'crates/yachtpit/crates/yachtpit');
|
||||||
logger.info(`🔨 Building in directory: ${buildCwd}`);
|
logger.info(`🔨 Building in directory: ${buildCwd}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -63,7 +64,7 @@ function bundleCrate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ───────────── Copy assets to public directory ──────────────────────────
|
// ───────────── Copy assets to public directory ──────────────────────────
|
||||||
const yachtpitDistDir = join(yachtpitPath, 'dist');
|
const yachtpitDistDir = join(buildCwd, 'dist');
|
||||||
|
|
||||||
logger.info(`📋 Copying assets to public directory...`);
|
logger.info(`📋 Copying assets to public directory...`);
|
||||||
|
|
||||||
@@ -152,6 +153,27 @@ function bundleCrate() {
|
|||||||
} else {
|
} else {
|
||||||
logger.info(`⚠️ ${indexHtml} not found – skipping HTML processing.`);
|
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() {
|
function cleanup() {
|
||||||
|
@@ -32,7 +32,6 @@ const BevySceneInner: React.FC<BevySceneProps> = ({
|
|||||||
position: 'absolute' as const,
|
position: 'absolute' as const,
|
||||||
inset: 0,
|
inset: 0,
|
||||||
zIndex: 0,
|
zIndex: 0,
|
||||||
pointerEvents: 'none' as const,
|
|
||||||
opacity: visible ? Math.min(Math.max(intensity, 0), 1) : 0,
|
opacity: visible ? Math.min(Math.max(intensity, 0), 1) : 0,
|
||||||
filter: glow ? 'blur(1px)' : 'none',
|
filter: glow ? 'blur(1px)' : 'none',
|
||||||
transition: `opacity ${speed}s ease-in-out`,
|
transition: `opacity ${speed}s ease-in-out`,
|
||||||
|
@@ -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: {
|
server: {
|
||||||
port: 3000,
|
port: 3000,
|
||||||
proxy: {
|
proxy: {
|
||||||
|
Reference in New Issue
Block a user