Skip to content

Commit 5d15dfd

Browse files
author
sw-yx
committed
fix reload relisten bug
1 parent 2404593 commit 5d15dfd

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

Diff for: .prettierrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

Diff for: bin/cmd.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ program.version(pkg.version);
1818
program
1919
.option("-c --config <webpack-config>", "additional webpack configuration")
2020
.option("-p --port <port>", "port to serve from (default: 9000)")
21-
.option("-t --timeout <timeout>", "function invocation timeout in seconds (default: 10)")
21+
.option(
22+
"-t --timeout <timeout>",
23+
"function invocation timeout in seconds (default: 10)"
24+
)
2225
.option("-s --static", "serve pre-built lambda files");
2326

2427
program
@@ -28,14 +31,21 @@ program
2831
console.log("netlify-lambda: Starting server");
2932
var static = Boolean(program.static);
3033
if (static) return; // early terminate, don't build
34+
var server;
3135
build.watch(cmd, program.config, function(err, stats) {
3236
if (err) {
3337
console.error(err);
3438
return;
3539
}
36-
40+
3741
console.log(stats.toString({ color: true }));
38-
var server = serve.listen(program.port || 9000, static, Number(program.timeout) || 10);
42+
if (!server) {
43+
server = serve.listen(
44+
program.port || 9000,
45+
static,
46+
Number(program.timeout) || 10
47+
);
48+
}
3949
stats.compilation.chunks.forEach(function(chunk) {
4050
server.clearCache(chunk.name);
4151
});
@@ -60,11 +70,13 @@ program
6070

6171
// error on unknown commands
6272
// ref: https://github.com/tj/commander.js#custom-event-listeners
63-
program
64-
.on('command:*', function () {
65-
console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
66-
process.exit(1);
67-
});
73+
program.on("command:*", function() {
74+
console.error(
75+
"Invalid command: %s\nSee --help for a list of available commands.",
76+
program.args.join(" ")
77+
);
78+
process.exit(1);
79+
});
6880

6981
program.parse(process.argv);
7082

0 commit comments

Comments
 (0)