{"id":13722430,"url":"https://github.com/aabccd021/bun-html-live-reload","last_synced_at":"2025-07-28T20:04:47.992Z","repository":{"id":117351221,"uuid":"609677366","full_name":"aabccd021/bun-html-live-reload","owner":"aabccd021","description":"Automatically reload html when Bun hot reloads","archived":false,"fork":false,"pushed_at":"2025-07-15T00:20:12.000Z","size":93,"stargazers_count":41,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-15T04:44:02.237Z","etag":null,"topics":["bun","live-reload"],"latest_commit_sha":null,"homepage":"","language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aabccd021.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-03-04T22:30:46.000Z","updated_at":"2025-07-15T00:20:15.000Z","dependencies_parsed_at":"2024-03-01T08:29:54.870Z","dependency_job_id":"cc01cca3-5006-4890-96aa-ae464c14f053","html_url":"https://github.com/aabccd021/bun-html-live-reload","commit_stats":{"total_commits":30,"total_committers":5,"mean_commits":6.0,"dds":"0.19999999999999996","last_synced_commit":"c4076b3b3dd89d62121c9c75439778ed100aa58b"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aabccd021/bun-html-live-reload","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aabccd021%2Fbun-html-live-reload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aabccd021%2Fbun-html-live-reload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aabccd021%2Fbun-html-live-reload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aabccd021%2Fbun-html-live-reload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aabccd021","download_url":"https://codeload.github.com/aabccd021/bun-html-live-reload/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aabccd021%2Fbun-html-live-reload/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267577976,"owners_count":24110350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bun","live-reload"],"created_at":"2024-08-03T01:01:28.673Z","updated_at":"2025-07-28T20:04:47.946Z","avatar_url":"https://github.com/aabccd021.png","language":"Nix","funding_links":[],"categories":["Extensions"],"sub_categories":["Utilities"],"readme":"# bun-html-live-reload\n\nHTML live reload for Bun\n\n## Getting Started\n\n```sh\nbun add -d bun-html-live-reload\n```\n\n```ts\n// example.ts\nimport { withHtmlLiveReload } from \"bun-html-live-reload\";\n\nBun.serve({\n  fetch: withHtmlLiveReload(async (request) =\u003e {\n    return new Response(\"\u003cdiv\u003ehello world\u003c/div\u003e\", {\n      headers: { \"Content-Type\": \"text/html\" },\n    });\n  }),\n});\n```\n\n- Run the server with `bun --hot example.ts`, open browser, and try to edit the `hello world` part.\n- The page should live reload as you edit!\n- This plugin relies on response header to identify html response,\n  so don't forget to add `\"Content-Type\": \"text/html\"` header to your `Response`.\n\n## Options\n\nYou can specify URL paths used for server-sent events and live reloader script.\n\n```ts\nBun.serve({\n  fetch: withHtmlLiveReload(\n    async (request) =\u003e {\n      /* ... */\n    },\n    {\n      // SSE Path\n      // default: \"/__dev__/reload\"\n      eventPath: \"/__reload\",\n\n      // Live reload script path\n      // default: \"/__dev__/reload.js\"\n      scriptPath: \"/__reload.js\",\n\n      // Wether to enable auto reload.\n      // If false, you need to manually call `reloadClients` function to reload clients.\n      // default: true\n      autoReload: false,\n    },\n  ),\n});\n```\n\n## Manually reload clients\n\nYou can manually reload clients (refresh tabs) by calling `reloadClients` function,\nin addition to auto reload feature.\n\n```ts\nimport { withHtmlLiveReload, reloadClients } from \"bun-html-live-reload\";\n\nBun.serve({\n  fetch: withHtmlLiveReload(async (request) =\u003e {\n    /* ... */\n  }),\n});\n\n// reload clients every second\nsetInterval(() =\u003e {\n  reloadClients();\n}, 1000);\n```\n\n# Changes from v0.1\n\n- Messages are sent through SSE (HTTP streaming) instead of Websocket.\n- Wraps only `fetch` function instead of the whole server.\n- Exposes `reloadClients` function to manually reload clients.\n- Uses separate javascript file instead of inline script to comply with strict CSP.\n- Supports multiple clients (tabs).\n- Added tests\n\n# Migration from v0.1\n\n## v0.1\n\n```ts\nimport { withHtmlLiveReload } from \"bun-html-live-reload\";\nimport { $ } from \"bun\";\n\nexport default Bun.serve(\n  withHtmlLiveReload(\n    {\n      fetch: (request) =\u003e {\n        /* ... */\n      },\n    },\n    {\n      watchPath: path.resolve(import.meta.dir, \"src\"),\n      buildConfig: {\n        entrypoints: [\"./src/index.tsx\"],\n        outdir: \"./build\",\n      },\n      onChange: async () =\u003e {\n        await $`rm -r ./dist`;\n      },\n    },\n  ),\n);\n```\n\n## v1.0\n\n```ts\nimport { withHtmlLiveReload, reloadClients } from \"bun-html-live-reload\";\nimport { FSWatcher, watch } from \"fs\";\nimport { $ } from \"bun\";\n\nconst buildConfig = {\n  entrypoints: [\"./src/index.tsx\"],\n  outdir: \"./build\",\n};\n\nBun.build(buildConfig);\n\nwatch(path.resolve(import.meta.url, \"src\")).on(\"change\", async () =\u003e {\n  await $`rm -r ./dist`;\n  await Bun.build(buildConfig);\n  reloadClients();\n});\n\nBun.serve({\n  fetch: withHtmlLiveReload(async (request) =\u003e {\n    /* ... */\n  }),\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faabccd021%2Fbun-html-live-reload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faabccd021%2Fbun-html-live-reload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faabccd021%2Fbun-html-live-reload/lists"}