Comparing version 1.0.1 to 1.0.2
@@ -26,2 +26,6 @@ const URL = "ws://" + location.host + "/browsermon"; | ||
}; | ||
ws.addEventListener("message", (event) => { | ||
if (event.data === "reload") window.location.reload(); | ||
}); | ||
} |
import http = require("http"); | ||
export default function browsermon({ server }: { server: http.Server }): void; | ||
export default function browsermon({ | ||
server, | ||
filename, | ||
}: { | ||
server: http.Server; | ||
filename?: string; | ||
}): void; |
13
index.js
@@ -5,2 +5,3 @@ const http = require("http"); | ||
const WebSocket = require("ws"); | ||
const watch = require("node-watch"); | ||
@@ -11,7 +12,13 @@ const browserJsContents = fs.readFileSync(path.join(__dirname, "browser.js")); | ||
wss.on("connection", (ws) => { | ||
wss.on("connection", (ws, filename) => { | ||
// client got connected ... | ||
// when a file got updated notify the browser | ||
if (filename) { | ||
watch(filename, { recursive: true }, () => { | ||
ws.send("reload"); | ||
}); | ||
} | ||
}); | ||
function browsermon({ server }) { | ||
function browsermon({ server, filename }) { | ||
if (process.env.NODE_ENV === "production") { | ||
@@ -37,3 +44,3 @@ // do nothing in production ... | ||
wss.handleUpgrade(req, socket, head, (ws, req) => { | ||
wss.emit("connection", ws, req); | ||
wss.emit("connection", ws, filename); | ||
}); | ||
@@ -40,0 +47,0 @@ } |
{ | ||
"name": "browsermon", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Automatically reload browser when nodemon restarts http server during development", | ||
@@ -27,4 +27,5 @@ "main": "./index.js", | ||
"dependencies": { | ||
"node-watch": "^0.7.1", | ||
"ws": "^7.5.0" | ||
} | ||
} | ||
} |
3750
74
2
+ Addednode-watch@^0.7.1
+ Addednode-watch@0.7.4(transitive)