Skip to content

Commit

Permalink
Add live reload to wrangler pages dev (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
GregBrimble authored Jan 8, 2022
1 parent 5e1222a commit 6fc2276
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-sloths-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Add `--live-reload` option to `wrangler pages dev` which automatically reloads HTML pages when a change is detected
13 changes: 13 additions & 0 deletions packages/wrangler/src/pages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,11 @@ export const pages: BuilderCallback<unknown, unknown> = (yargs) => {
description: "Durable Object to bind (NAME=CLASS)",
alias: "o",
},
"live-reload": {
type: "boolean",
default: false,
description: "Auto reload HTML pages when change is detected",
},
// TODO: Miniflare user options
});
},
Expand All @@ -753,6 +758,7 @@ export const pages: BuilderCallback<unknown, unknown> = (yargs) => {
binding: bindings = [],
kv: kvs = [],
do: durableObjects = [],
"live-reload": liveReload,
"--": remaining = [],
}) => {
if (!local) {
Expand Down Expand Up @@ -906,6 +912,7 @@ export const pages: BuilderCallback<unknown, unknown> = (yargs) => {
kvPersist: true,
durableObjectsPersist: true,
cachePersist: true,
liveReload,

...miniflareArgs,
});
Expand All @@ -924,6 +931,12 @@ export const pages: BuilderCallback<unknown, unknown> = (yargs) => {
} catch {}
}

if (directory !== undefined && liveReload) {
watch([directory], { persistent: true }).on("all", async () => {
await miniflare.reload();
});
}

EXIT_CALLBACKS.push(() => {
server.close();
miniflare.dispose().catch((err) => miniflare.log.error(err));
Expand Down

0 comments on commit 6fc2276

Please sign in to comment.