Created
December 7, 2025 07:26
-
-
Save hUwUtao/96ea1da1921632fd961332e53e1ed500 to your computer and use it in GitHub Desktop.
Bun bundler dev & single-bundle build serve
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
| /* | |
| This is suppose to bridge the gap between bun production bundler and elysia, while managing to make it work without building the server bundle. | |
| Suppose to build a single executable server with SPA. | |
| https://bun.com/reference/bun/HTMLBundle | |
| */ | |
| import Elysia from "elysia"; | |
| import indexHtml from "../public/index.html"; | |
| const built = !!indexHtml.files | |
| function remap(path: string): string { | |
| let p = path | |
| if (p.endsWith("index.html") || p.endsWith(indexHtml.index)) { | |
| p = "" | |
| } | |
| else if (p.startsWith("/$bunfs/root/")) { | |
| p = p.slice("/$bunfs/root/".length) | |
| } | |
| return p | |
| } | |
| const frontend = built ? indexHtml.files?.reduce((ely, file) => ely.get(remap(file.path), () => new Response(Bun.file(file.path), { | |
| headers: { | |
| ...file.headers | |
| } | |
| })), new Elysia()) : await (async () => { | |
| let build = await Bun.build({ | |
| entrypoints: ["./public/index.html"], | |
| minify: false, | |
| sourcemap: "linked" | |
| }) | |
| return build.outputs.reduce((ely, file) => ely.get(remap(file.path.slice(2)), () => new Response(file, { | |
| headers: { | |
| "Content-Type": file.type | |
| } | |
| })), new Elysia()) | |
| })() | |
| export default frontend |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this about packaging the entire service (including HTML, JS, CSS, and Elysia logic) into a single binary file?