fix: VisionMask CJS->ESM, content-hashed bundle, Cloudflare cache bypass

VisionMask: module.exports -> export default (was breaking as F.VisionMask is not a constructor)
Build system: content-hashed bundles (bundle.HASH.js) bypass Cloudflare's 4h edge cache
Nginx: no-cache headers for .js and index.html
HTML: inline diagnostic script + versioned bundle URL
Diagnostic: try/catch on create(), debug crosshair + text overlay, per-component logging
Phaser: banner=true, debug physics, window.__IR_GAME export
This commit is contained in:
2026-05-23 07:47:23 +00:00
parent f37e71d5c7
commit b238fb2ee9
5 changed files with 48 additions and 2 deletions

24
build.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
# Build script: webpack + content-hashed filename for permanent cache-busting
set -e
cd "$(dirname "$0")"
# Build webpack
npx webpack --mode production
# Generate content hash for bundle.js
BUNDLE_HASH=$(md5sum dist/bundle.js | cut -c1-8)
BUNDLE_FILE="bundle.${BUNDLE_HASH}.js"
mv dist/bundle.js "dist/${BUNDLE_FILE}"
BUILD_TS=$(date +%s)
# Rewrite HTML: replace bundle.js?v=TIMESTAMP with content-hashed filename
# and inject timestamp for diagnostic script
sed -i "s|bundle\.js?v=BUILD_TIMESTAMP|${BUNDLE_FILE}|g" dist/index.html
sed -i "s/BUILD_TIMESTAMP/${BUILD_TS}/g" dist/index.html
# Copy assets that webpack ignores
cp tundra_background.png dist/
echo "[build] done — bundle: ${BUNDLE_FILE} (build ${BUILD_TS})"

View File

@@ -9,6 +9,16 @@
html, body { width: 100%; height: 100%; overflow: hidden; background: #1a1a2e; }
canvas { display: block; image-rendering: pixelated; }
</style>
<!-- INLINE DIAGNOSTIC — runs before bundle, confirms page loads -->
<script>
window.__IR_BOOT = { time: Date.now(), deploy: 'BUILD_TIMESTAMP' };
console.log('[IR:page] HTML loaded, deploy:', new Date().toISOString());
console.log('[IR:page] navigator.userAgent:', navigator.userAgent.substring(0, 80));
window.addEventListener('error', function(e) {
console.error('[IR:page] GLOBAL ERROR:', e.message, 'at', e.filename, ':', e.lineno);
});
</script>
<script defer src="bundle.js?v=BUILD_TIMESTAMP"></script>
</head>
<body>
<div id="game-container"></div>

View File

@@ -5,6 +5,18 @@ server {
root /usr/share/nginx/html;
index index.html;
# Force fresh fetch for bundle.js (Cloudflare was caching stale deploys)
location ~* \.js$ {
add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
expires -1;
}
# Also prevent HTML caching so inline diagnostic scripts take effect
location = /index.html {
add_header Cache-Control "no-store, no-cache, must-revalidate, max-age=0";
expires -1;
}
location / {
try_files $uri /index.html;
}

View File

@@ -5,7 +5,7 @@ import Phaser from 'phaser';
import { GameLoopScene } from './GameLoopScene.js';
import { Tank } from '../entities/Tank.js';
import { Turret } from '../entities/Turret.js';
import { VisionMask } from '../systems/VisionMask.js';
import VisionMask from '../systems/VisionMask.js';
import { PatternManager } from '../systems/PatternManager.js';
import { SaveManager } from '../../systems/SaveManager.js';
import { CommanderHatch } from '../entities/CommanderHatch.js';

View File

@@ -167,4 +167,4 @@ class VisionMask {
}
}
module.exports = VisionMask;
export default VisionMask;