fix: copy game data to /data instead of /data/src/data - #8
Merged
Conversation
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
There was a problem hiding this comment.
🟢 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-copytarget config to userename: { stripBase: 2 }sosrc/data/**is copied underdata/**. - Normalize
destfrom"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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
A fresh scaffold does not run.
npm create melonjs@latest my-game && cd my-game && npm install && npm run devboots, then fails:npm run buildis wrong in the same way, it just fails silently: the assets land indist/data/src/data/fnt/rather thandist/data/fnt/.Cause
vite-plugin-static-copy4 keeps the whole matched path underdest. IncollectCopyTargets,destDir = path.join(dest, dir)wherediris the matched file's directory relative to the project root, so:The dev middleware keys its file map off that same value, so
/data/fnt/PressStart2P.pngmisses, falls through to the SPA fallback, and comes back asindex.htmlwithContent-Type: text/html— which is why the failure looks like a loader problem rather than a path problem.src/manifest.tsasks for/data/fnt/PressStart2P.png, so nothing resolves.Fix
rename: { stripBase: 2 }drops the two leadingsrc/datasegments, which is what version 4 added the option for. Same change invite.config.tsandvite.electron.config.ts. No dependency bump:stripBaseis present in 4.0.1, which^4.0.1already covers.Verified
On a clean checkout of
mainwith the patch applied (vite 8.2.2, vite-plugin-static-copy 4.1.1):GET /data/fnt/PressStart2P.png(dev)200 text/html(651 B, index.html)200 image/png(2950 B)vite builddist/data/src/data/fnt/...dist/data/fnt/...vite build --config vite.electron.config.tsdist/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 --noEmitpasses.🤖 Generated with Claude Code
https://claude.ai/code/session_01Q8aCt5SwH5D5Bi7qKXi2X8
Generated by Claude Code