fix(build): copy frontend build output to embed target when frontend:dir is non-default#5251
Conversation
…dir is non-default When the frontend directory is configured via frontend:dir in wails.json to a non-default path (e.g. ./jsfrontend), the build system correctly builds the frontend in that directory but the Go embed directive still references frontend/dist. This means the built assets are not included in the compiled binary. After BuildFrontend, if the actual frontend directory differs from the default frontend/ directory, the built dist files are copied to the embed target directory discovered via static analysis of //go:embed directives. Fixes #5034
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughAdds SyncFrontendDistToEmbedTarget and integrates it into Build: it detects embed target directories via staticanalysis, copies a custom frontend's built dist into those embed-target dist folders, and returns a deferred cleanup that removes copied files and restores ChangesFrontend Dist Synchronization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
🤖 PR Triage Review ✅ Accepted This PR fixes a build issue where frontend assets aren't copied to the embed target when using a custom Changes: 234 additions, 2 files changed Platform: All (v2-only, build system) Next Steps: Dispatching for testing on all platforms. Reviewed by Wails PR Reviewer Bot |
|
test |
|
Tested on macOS (darwin/arm64) — verdict: ✓ pass
Unit test output |
SyncFrontendDistToEmbedTarget now returns a cleanup func that removes the copied assets and restores a .gitkeep placeholder after the build completes, keeping the working tree clean. The cleanup runs via defer so it fires whether the build succeeds or fails.
|
Added cleanup in 5945771 — Behaviour:
New test: |
Description
Fixes #5034
When
frontend:dirinwails.jsonis set to a non-default path (e.g.,./jsfrontend), the build system correctly builds the frontend in that directory, but the//go:embed all:frontend/distdirective inmain.gostill referencesfrontend/dist. This means the built assets (only agitkeepplaceholder) are not correctly included in the compiled binary, causing it to fail to start.Changes
SyncFrontendDistToEmbedTargetfunction called afterBuildFrontendfrontend/, discovers embed targets viastaticanalysis.GetEmbedDetailsand copies the built dist files to the embed target directoryfrontend/directoryTesting
v2/test/5034/frontend_dir_test.go:TestSyncFrontendDistToEmbedTarget: verifies files are copied correctly when frontend:dir is non-defaultTestSyncFrontendDistNoOpWhenDefault: verifies no changes when using default dirTestSyncFrontendDistNoOpWhenNoDistInEmbed: verifies no errors when no dist embed dirs foundTestEmbedDiscoveryInTempDir: verifies embed discovery works in temp dirsLimitations
This fix does NOT address the case where
frontend:dirpoints outside the project directory (e.g.,"../frontend"), as Go's//go:embeddirective cannot reference paths outside the module. Users in that situation need to manually update their embed directive.Summary by CodeRabbit
New Features
Tests