Skip to content

Commit 269de4c

Browse files
committed
fix rebuild on changed file for server
1 parent efd992c commit 269de4c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

resources/watch.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,25 @@ function startWatch() {
5252
}
5353

5454
function deleteFile(fileName) {
55-
delete require.cache[fileName];
55+
clearCache(fileName);
5656
build().catch(error => console.error(error.stack || error));
5757
}
5858

5959
function changeFile(fileName) {
60-
delete require.cache[fileName];
60+
clearCache(fileName);
6161
build().catch(error => console.error(error.stack || error));
6262
}
6363

64+
function clearCache(causeFileName) {
65+
if (path.extname(causeFileName) === '.js') {
66+
for (var fileName in require.cache) {
67+
if (fileName.indexOf('/node_modules/') === -1) {
68+
delete require.cache[fileName];
69+
}
70+
}
71+
}
72+
}
73+
6474
if (require.main === module) {
6575
watch().catch(error => console.error(error.stack || error));
6676
}

0 commit comments

Comments
 (0)