Make more robust against restarts by external watcher, such as nodemon

master
Sven Slootweg 3 years ago
parent be4cb973b4
commit 28dfcfbc5d

@ -50,8 +50,6 @@ module.exports = function ({ options, staticPath, staticBasePath, entryPaths, ho
}
let budoOptions = {
watchGlob: staticPath(options.livereloadPattern),
live: options.livereloadPattern,
livePort: defaultValue(options.livereloadPort, 35729),
stream: defaultValue(options.stream, process.stdout),
port: options.port,
@ -61,15 +59,33 @@ module.exports = function ({ options, staticPath, staticBasePath, entryPaths, ho
browserify: options.browserify,
middleware: middlewareList,
debug: defaultValue(options.sourceMaps, true),
verbose: true
};
let devServer = budo(entryPaths, budoOptions).on("connect", (event) => {
let reloadServer = event.webSocketServer;
let devServer = budo(entryPaths, budoOptions)
.watch(staticPath(options.livereloadPattern), {
awaitWriteFinish: {
// NOTE: This is mostly just a hack to make sure that the process has time to get restarted (by eg. nodemon) before sending out a LiveReload update. Need to investigate whether there's a less hacky way to do this.
stabilityThreshold: 130
}
})
.live()
.on("watch", (event, file) => {
if (event === "change" || event === "add") {
devServer.reload(file);
}
})
.on("pending", () => {
// This event is called when the bundle is being regenerated, ie. after watchify has detected a change in the input files
devServer.reload(fullBundlePath);
})
.on("connect", (event) => {
let reloadServer = event.webSocketServer;
reloadServer.once("connection", (_socket) => {
// This is to make sure the browser also reloads after the process has auto-restarted (eg. using `nodemon`)
console.log("Triggering initial page refresh for new client...");
devServer.reload("*");
reloadServer.once("connection", (_socket) => {
// This is to make sure the browser also reloads after the process has auto-restarted (eg. using `nodemon`)
console.log("Triggering initial page refresh for new client...");
devServer.reload("*");
});
});
});
};

Loading…
Cancel
Save