From 40b93b9c2722e85a000de62e3eb8bc02facafd10 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 28 May 2023 22:39:22 +0800 Subject: [PATCH] fix: properly close the watcher after tests --- src/pluginWebpack4.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pluginWebpack4.ts b/src/pluginWebpack4.ts index fb066987..335a6a0a 100644 --- a/src/pluginWebpack4.ts +++ b/src/pluginWebpack4.ts @@ -171,6 +171,15 @@ class VueLoaderPlugin { watcher.close() } }) + + // In some cases, e.g. in this project's tests, + // even though needsHMR() returns true, webpack is not watching, thus no watchClose hook is called. + // So we need to close the watcher when webpack is done. + compiler.hooks.done.tap(id, () => { + if (watcher) { + watcher.close() + } + }) } } }