Skip to content

fix: copy game data to /data instead of /data/src/data - #8

Merged
obiot merged 1 commit into
mainfrom
fix/static-copy-data-paths
Sep 5, 2026
Merged

fix: copy game data to /data instead of /data/src/data#8
obiot merged 1 commit into
mainfrom
fix/static-copy-data-paths

Conversation

@obiot

@obiot obiot commented Sep 4, 2026

Copy link
Copy Markdown
Member

The bug

A fresh scaffold does not run. npm create melonjs@latest my-game && cd my-game && npm install && npm run dev boots, then fails:

Failed loading resource /data/fnt/PressStart2P.png

npm run build is wrong in the same way, it just fails silently: the assets land in dist/data/src/data/fnt/ rather than dist/data/fnt/.

Cause

vite-plugin-static-copy 4 keeps the whole matched path under dest. In collectCopyTargets, destDir = path.join(dest, dir) where dir is the matched file's directory relative to the project root, so:

src: "src/data/**/*"  +  dest: "data/"   ->   data/src/data/fnt/PressStart2P.png

The dev middleware keys its file map off that same value, so /data/fnt/PressStart2P.png misses, falls through to the SPA fallback, and comes back as index.html with Content-Type: text/html — which is why the failure looks like a loader problem rather than a path problem.

src/manifest.ts asks for /data/fnt/PressStart2P.png, so nothing resolves.

Fix

rename: { stripBase: 2 } drops the two leading src/data segments, which is what version 4 added the option for. Same change in vite.config.ts and vite.electron.config.ts. No dependency bump: stripBase is present in 4.0.1, which ^4.0.1 already covers.

Verified

On a clean checkout of main with the patch applied (vite 8.2.2, vite-plugin-static-copy 4.1.1):

before after
GET /data/fnt/PressStart2P.png (dev) 200 text/html (651 B, index.html) 200 image/png (2950 B)
vite build dist/data/src/data/fnt/... dist/data/fnt/...
vite build --config vite.electron.config.ts dist/data/src/data/fnt/... dist/data/fnt/...

Booted the dev server in a headless browser: Hello World! renders in the bitmap font and the console is clean, no failed resources. tsc --noEmit passes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q8aCt5SwH5D5Bi7qKXi2X8


Generated by Claude Code

vite-plugin-static-copy 4 keeps the whole matched path under `dest`, so
`src: "src/data/**/*"` with `dest: "data/"` writes the files to
`data/src/data/...`. Nothing then resolves at the `/data/...` URLs the
manifest uses: `npm run dev` fails to load PressStart2P.png (the SPA
fallback answers with index.html), and `npm run build` lays the same
wrong tree into dist.

Strip the two leading `src/data` segments so both the dev server and the
build serve the assets where the manifest looks for them. Applied to the
web and the Electron config alike.

Verified on a fresh scaffold: dev serves /data/fnt/PressStart2P.png as
image/png, the game boots with a clean console, and both builds produce
dist/data/fnt/.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q8aCt5SwH5D5Bi7qKXi2X8
Copilot AI lite review requested due to automatic review settings September 4, 2026 12:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes correctly align static asset output paths with the /data/... URLs used at runtime and are consistently applied across both Vite configs.

Pull request overview

Fixes an asset path bug in the Vite dev server and build outputs by ensuring static game data is copied to /data/** (rather than /data/src/data/**), matching runtime asset URLs referenced by the game manifest.

Changes:

  • Update vite-plugin-static-copy target config to use rename: { stripBase: 2 } so src/data/** is copied under data/**.
  • Normalize dest from "data/" to "data" in both Vite configs while applying the same strip behavior.
File summaries
File Description
vite.config.ts Adjusts static copy settings so src/data/**/* lands under dist/data/** as expected by /data/... asset URLs.
vite.electron.config.ts Applies the same static copy path fix for the Electron build/dev configuration.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@obiot
obiot merged commit b0aa001 into main Sep 5, 2026
1 check passed
obiot pushed a commit to melonjs/melonjs.org that referenced this pull request Sep 5, 2026
melonjs/typescript-boilerplate#8 is merged, and create-melonjs degits main
at scaffold time, so a fresh project now serves its data from src/data
with no intervention. Remove the "Make the assets load" step, put the
file tree and the asset copy back on src/data, and let the reader open
the dev server straight after npm run dev.

Verified by scaffolding from scratch: npm create melonjs, npm install,
npm run dev, and /data/fnt/PressStart2P.png comes back as image/png with
Hello World rendering on a clean console.

Running the rest of the tutorial against that scaffold showed three
"You should see" lines that do not match what happens:

- Part 3-2 said the level appears once level.load runs. It does not. The
  map places the character, the stub renderable throws on the missing
  texture, and loading stops before anything is drawn, so the screen is
  black. Say that, and explain why.
- Part 3-3 step 1 said the character falls through the floor. It has no
  body yet, so nothing falls, and the camera is still at the map corner
  so the character is not even on screen. What does appear is the level.
- Step 2 said the character stands on the ground. Still off camera, so
  nothing looks different; the change only becomes visible in step 3.

Step 3, where the camera starts following, is the step that actually pays
off, so the payoff line moves there.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q8aCt5SwH5D5Bi7qKXi2X8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants