From 2d2c91a53d6cfbb2e26a187e37defceae10c6336 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 19 Apr 2023 10:28:50 +0800 Subject: [PATCH] fix: fix watcher unlink listener setup timing --- packages/plugin-vue/src/index.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/plugin-vue/src/index.ts b/packages/plugin-vue/src/index.ts index 96774f0c..914702c0 100644 --- a/packages/plugin-vue/src/index.ts +++ b/packages/plugin-vue/src/index.ts @@ -162,15 +162,16 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { configureServer(server) { options.devServer = server - if (options.compiler.invalidateTypeCache) { - server.watcher.on('unlink', (file) => { - options.compiler.invalidateTypeCache(file) - }) - } }, buildStart() { - options.compiler = options.compiler || resolveCompiler(options.root) + const compiler = (options.compiler = + options.compiler || resolveCompiler(options.root)) + if (compiler.invalidateTypeCache) { + options.devServer?.watcher.on('unlink', (file) => { + compiler.invalidateTypeCache(file) + }) + } }, async resolveId(id) {