-
-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add dev pages add reload + vite hmr add getInputFileName add debounce comment rollback chunkFileNames use only reloadOnUpdated add line edit script check document hidden edit server code
- Loading branch information
1 parent
68ab80d
commit 5f83062
Showing
9 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import { createRoot } from "react-dom/client"; | ||
import App from "@src/pages/content/components/Demo/app"; | ||
import reloadOnUpdated from "@src/reload/client"; | ||
|
||
const root = document.createElement("div"); | ||
root.id = "chrome-extension-boilerplate-react-vite-content-view-root"; | ||
document.body.append(root); | ||
|
||
createRoot(root).render(<App />); | ||
|
||
reloadOnUpdated(); |
This file contains 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 file contains 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 file contains 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 file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
let needToReload = false; | ||
|
||
export default function reloadOnUpdated() { | ||
// reload | ||
function reload() { | ||
window.location.reload(); | ||
socket.send("remove"); | ||
} | ||
|
||
// reload when document visible | ||
document.addEventListener("visibilitychange", () => { | ||
!document.hidden && needToReload && reload(); | ||
}); | ||
|
||
// reload server setting | ||
const socket = new WebSocket("ws://localhost:8081"); | ||
socket.addEventListener("open", () => { | ||
socket.send("add"); | ||
}); | ||
socket.addEventListener("message", (event) => { | ||
if (event.data !== "update") { | ||
return; | ||
} | ||
// disable reload when document hidden | ||
if (document.hidden) { | ||
needToReload = true; | ||
return; | ||
} | ||
reload(); | ||
}); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { WebSocketServer, WebSocket } from "ws"; | ||
import chokidar from "chokidar"; | ||
import { clearTimeout } from "timers"; | ||
|
||
const PORT = 8081; | ||
const wss = new WebSocketServer({ port: PORT }); | ||
|
||
const wsSet: Set<WebSocket> = new Set(); | ||
|
||
console.log("ws server:" + PORT); | ||
|
||
wss.on("connection", (ws) => { | ||
ws.addEventListener("message", (event) => { | ||
switch (event.data) { | ||
case "add": | ||
return wsSet.add(ws); | ||
case "remove": | ||
return wsSet.delete(ws); | ||
} | ||
}); | ||
}); | ||
|
||
let timer: NodeJS.Timeout; | ||
const DELAY = 200; | ||
chokidar.watch("dist").on("all", () => { | ||
clearTimeout(timer); | ||
// debounce | ||
timer = setTimeout(() => { | ||
wsSet.forEach((ws) => ws.send("update")); | ||
}, DELAY); | ||
}); |
This file contains 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