/phaser4-gamedev:phaser-build runs instead · from phaser4-gamedev
Compiles, runs, and deploys Phaser 4 projects with Vite. Handles dev server, production builds, TypeScript type checking, and common build errors like missing modules or asset 404s.
This skill never runs in Claude Code
It ships in phaser4-gamedev at skills/, but /phaser4-gamedev:phaser-build (a command, or a skill Claude Code finds first) has the same name: typing it, or Claude choosing it, runs that one instead.
Start the dev server with hot reload:
npm run dev
Serves at http://localhost:5173 by default — Vite picks the next free port if that is taken, so read the URL it prints. Changes auto-reload in the browser.
npm run build # tsc --noEmit + vite build → dist/
npm run preview # serve dist/ locally
npm run playtest:build # build + run every scenario against the minified bundle
Output in dist/ — static files ready for any web host.
Run the validation script before building:
bash "${CLAUDE_PLUGIN_ROOT}/skills/phaser-build/scripts/validate-project.sh" .
The script checks for common issues automatically.
npx tsc --noEmit
Fix all type errors before shipping. Common Phaser 4 TypeScript issues:
Missing Phaser types:
// tsconfig.json — Phaser 4 resolves its own types via its exports map
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "bundler",
"skipLibCheck": true
}
}
Then import it explicitly in each file: import Phaser from 'phaser';
If you see TS2688: Cannot find type definition file for 'Phaser', the project is carrying
the v3-era typeRoots + types: ["Phaser"] pair. Delete both keys — Phaser 4 ships a single
types/phaser.d.ts, which is not a valid type-root package.
this.input.keyboard nullable:
// Wrong:
const cursors = this.input.keyboard.createCursorKeys();
// Correct:
const cursors = this.input.keyboard!.createCursorKeys();
sprite.body nullable:
// Wrong:
sprite.body.velocity.x
// Correct:
(sprite.body as Phaser.Physics.Arcade.Body).velocity.x
// Or:
sprite.body?.velocity.x
this.scene.get() returns base Scene type:
// Cast to specific scene class:
const game = this.scene.get('GameScene') as GameScene;
npm install phaser # installs Phaser 4 (latest stable). Do NOT use phaser — that tag still points at 4.2.1
In Vite, assets must be in the public/ directory. They are served as-is at the root.
✅ public/assets/images/sky.png → loads as 'assets/images/sky.png'
❌ src/assets/images/sky.png → won't work with this.load.image()
Never import assets via ES imports for Phaser. Just reference the path string:
this.load.image('sky', 'assets/images/sky.png'); // ✅
v3 → v4 breaking change. Replace with Vector2:
// Old (v3):
const pt = new Phaser.Geom.Point(x, y);
// New (v4):
const pt = new Phaser.Math.Vector2(x, y);
v3 → v4 breaking change:
// Old (v3):
const angle = Math.PI2; // was π (wrong!) in v3
// New (v4):
const angle = Math.TAU; // π×2
const half = Math.PI_OVER_2; // π/2
scene: [] array<div id="game-container"> if using parent: 'game-container'parent config to append to document.body directly// Try Canvas renderer as fallback
const config = {
type: Phaser.CANVAS, // instead of Phaser.AUTO or Phaser.WEBGL
// ...
};
Or add WebGL context loss recovery listener:
this.game.renderer.on('contextlost', () => {
console.warn('WebGL context lost — attempting recovery');
});
Projects from /phaser-new already have the production config; the canonical copy is
skills/phaser-init/template/vite.config.ts. What matters in it, for Vite 8:
// vite.config.ts (excerpt)
export default defineConfig({
base: './', // relative: works on itch.io, GitHub Pages sub-paths, Netlify, Capacitor
plugins: [contentSecurityPolicy()], // CSP <meta> injected at build only
build: {
target: 'es2022',
sourcemap: false, // don't publish your source
chunkSizeWarningLimit: 2000,
rolldownOptions: {
output: {
// Phaser in its own long-cached chunk; patches only re-download your code.
codeSplitting: { groups: [{ name: 'phaser', test: /node_modules[\\/]phaser/ }] },
},
},
},
});
Vite 8 bundles with Rolldown and minifies with Oxc. Two consequences for older configs:
minify: 'terser' fails the build (terser not found) unless terser is
installed. Delete the line; the default is faster and comparable in size.build.rollupOptions.output.manualChunks: { phaser: ['phaser'] } no longer works —
Rolldown dropped the object form. Use rolldownOptions.output.codeSplitting.groups as above.base: './' is critical. With the default /, assets resolve from the domain root
and 404 on any sub-path host (itch.io, user.github.io/repo/). Relative works everywhere
a single-page game is served, so there is no need for a per-host base.
This section covers the mechanics of getting a build onto a host. For deciding whether the game is ready — the readiness gate, versioning, store presence, launch day — see
skills/phaser-release/. For CSP, headers, secrets and supply chain, seereferences/production-hardening.md.
Whatever the host: ship a clean build. --mode build playtests build with
VITE_PLAYTEST=true, which keeps the test hook in dist/. Run a plain npm run build
immediately before packaging or uploading.
npm run verify, then npm run builddist/ (cd dist && zip -r ../game.zip .) — not the folderProjects from /phaser-new include .github/workflows/deploy-pages.yml: on a v* tag
or a manual run it runs npm run verify, rebuilds clean, and deploys with the official
actions/upload-pages-artifact + actions/deploy-pages. Every action is pinned to a
full commit SHA, and only the deploy job gets pages: write / id-token: write. One-time
setup: repo Settings → Pages → Source: GitHub Actions. For an older project, copy
the workflow from skills/phaser-init/template/.github/workflows/.
Avoid third-party deploy actions that push to a gh-pages branch with a write token: the
official flow needs no branch, no contents: write, and no extra trust.
Connect the git repo. Set:
npm run builddistBoth auto-deploy on push to main. Add security headers with a public/_headers file
(Netlify, Cloudflare Pages) or vercel.json — see references/production-hardening.md.
npm install @capacitor/core @capacitor/cli @capacitor/ios @capacitor/android
npx cap init
npx cap add ios
npx cap add android
npm run build
npx cap sync
npx cap open ios # Opens Xcode
npx cap open android # Opens Android Studio
arcade: { debug: false } in GameConfigmaxParticles set on all particle emittersnpm run verify passes (typecheck, unit tests, every scenario on the production build)For a detailed performance playbook (measurement-first prompting, per-frame allocation elimination, spatial grid, audio lazy-load, atlas packing, tween leak fixes), see
skills/phaser-analyze/references/performance-playbook.md. Use/phaser-analyzefor a full project audit before shipping if FPS is a concern.
Run the project validator:
bash "${CLAUDE_PLUGIN_ROOT}/skills/phaser-build/scripts/validate-project.sh" .
The validator checks: Phaser version, tsconfig fields, scene registration, removed v3
APIs, Vite 8 config pitfalls, CSP, secret-looking VITE_* variables, listener leaks and
asset-key consistency. Exit 0 = no errors, 1 = errors.
references/production-hardening.md — CSP, response headers, secrets, supply chain, client trustreferences/testing-patterns.md — Vitest for pure logic, playtest scenarios for runtimeWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub yakoub-ai/phaser4-gamedev --plugin phaser4-gamedev26 skills in this plugin
/phaser-analyzeThis skill should be used when the user asks to "analyze my game", "review my Phaser project", "audit project health", "find bottlenecks", "refactor my game", "improve my code", "optimize my project", "what's wrong with my game", "code review Phaser", or "assess architecture"./phaser-animationThis skill should be used when the user asks to "create animation", "animate sprite", "add tweens", "sprite animation not playing", "character animations", "easing", "tween timeline", "idle animation", "walk animation", "fade in", "fade out", or "scale animation"./phaser-architectThis skill should be used when the user asks to design a Phaser 4 game, plan game architecture, structure scenes, organize game state, define scene flow, choose module boundaries, or review/refactor an existing Phaser project architecture before implementation.Other plugins' skills for the same job