Automatically handle Vite hot file during static site generation#213
Automatically handle Vite hot file during static site generation#213JoshSalway wants to merge 4 commits intostatamic:4.xfrom
Conversation
|
Hi @duncanmcclean — wanted to offer some options here depending on how much change you're comfortable with. I've experimented with all four approaches as sequential commits in this branch so you can review each one directly in the commit history. Option 1 — Documentation only (least invasive)Commit: No code change. Adds a note to the README explaining that Option 2 — Warn onlyCommit: Prints a clear warning before generation if Option 3 — Automatically handle it (recommended)Commit: Moves Option 4 — Fail hardBranch: Aborts generation entirely if The first commit in the branch ( Happy to adjust or split however works best for you. 🤖 Generated with Claude Code |
Previously, if a path configured in the `copy` config did not exist (e.g. `public/build` before running `npm run build`), `copyDirectory()` would silently return false and the generator would still print a success message. This caused Vite assets to appear missing in the static output with no indication of what went wrong. Now a clear warning is printed and the copy is skipped, making it obvious when a configured source path is missing. Fixes statamic#185 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When public/hot exists, Vite serves assets from the dev server (localhost) instead of the production build, causing broken asset URLs in the generated HTML. Added a note to the Netlify deployment docs explaining this. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When public/hot exists, Vite generates asset URLs pointing to the dev server (http://localhost:5173/...) instead of the production build. The generator now warns the user before generating so they know the output may have broken asset URLs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Rather than warning or aborting, automatically move public/hot to public/hot.ssg-backup before generating, then restore it afterwards (even if generation fails). This ensures asset URLs always resolve from the production manifest without disrupting the developer's local workflow. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2364337 to
128453f
Compare
Summary
Fixes #185
When
public/hotexists (created bynpm run dev), Laravel's Vite helper switches to HMR mode and generates asset URLs pointing tohttp://localhost:5173/...instead of production build assets. The SSG would silently write these localhost URLs into every generated HTML file — all Vite-managed CSS and JS would be completely broken in any deployed static site, with no indication of what went wrong.Reproduction
Confirmed locally on a real Statamic site:
Without
public/hot— correct production URLs:With
public/hot— broken localhost URLs, SSG reports success with no warning:Fix
Before generating content files, the generator now automatically moves
public/hotaside topublic/hot.ssg-backup, runs generation (so Vite resolves assets from the production manifest), then restores the hot file — even if generation fails. The developer's local environment is left exactly as it was.This also includes a second improvement: if a path in the
copyconfig doesn't exist, a warning is now shown rather than silently skipping it.Test plan
it_temporarily_moves_vite_hot_file_aside_during_generation— hot file moved aside, correct URLs generated, hot file restoredit_restores_vite_hot_file_even_if_generation_fails— hot file always restored even on failureit_warns_when_copy_source_does_not_exist— warning for missing copy sourcesit_copies_files_and_directories_to_destination— happy path still works🤖 Generated with Claude Code