feat(server): embed web UI assets in binary and serve locally#15700
feat(server): embed web UI assets in binary and serve locally#15700BYK wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: Found a related PR: PR #12829: feat(app): embed web ui in binary This appears to be a previous attempt at the same feature - embedding the web UI in the binary. This PR (#15700) may be a revived or refactored version of that earlier work, or it could be addressing the same goal with a different implementation approach. |
Build the web UI into the binary at compile time via a generated app-manifest. The server serves embedded assets directly instead of proxying everything to the CDN, with a CDN fallback for when no local assets are present. - build.ts generates src/server/app-manifest.ts mapping URL paths to embedded $bunfs asset paths; uses a Bun plugin with loader:"file" so non-JS assets are embedded as opaque blobs rather than parsed - Optional Nerd Font woff2/woff/ttf files (83 files, ~27MB) are excluded from the manifest and transparently proxied from CDN on demand; core fonts (Inter, IBM Plex Mono) remain embedded - server.ts gains serveStaticFile() for exact-match serving (used in pre-bootstrap middleware to avoid DB migration on asset requests) and serveLocal() with SPA fallback (used in catch-all after API routes) - Asset resolution order: embedded $bunfs → OPENCODE_APP_DIR env → auto-detect packages/app/dist → CDN proxy - SPA fallback skips paths with file extensions so unmatched assets fall through to CDN proxy instead of returning index.html - Binary size: ~159MB (v1.2.15) + 42MB embedded assets = ~201MB raw, 174MB after excluding optional fonts
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
Embeds the web UI into the compiled binary at build time so
opencode serveworks offline without proxying to the CDN.What
src/server/app-manifest.tsat compile time, mapping URL paths to embedded$bunfsasset paths. A Bun plugin withloader: "file"ensures non-JS assets (images, fonts, etc.) are embedded as opaque blobs rather than parsed as modules.serveStaticFile()(exact-match only, runs as middleware beforeInstance.provide()to avoid triggering DB migrations on asset requests) andserveLocal()(exact match + SPA fallback for extensionless page routes, used in the catch-all after all API routes).$bunfs→OPENCODE_APP_DIRenv var → auto-detectpackages/app/dist→ CDN proxy fallback.app.opencode.aion first use and browser-cached thereafter.font-display: swapensures immediate text rendering with fallback.Size impact