From 9933541af1306a26c9d7373a0e77268782dd5726 Mon Sep 17 00:00:00 2001 From: allen <272970666@qq.com> Date: Wed, 15 Nov 2023 00:04:21 +0800 Subject: [PATCH] fix: build mode watch file --- src/index.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index b6fdf8a..184dcf4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,18 +6,20 @@ type Options = Partial<{ storeDir: string excludes: string[] outputFile: string + isDev: boolean; }> const defaultOptions: Options = { storeDir: 'src/store', excludes: ['index'], outputFile: 'src/helper/pinia-auto-refs.ts', + isDev: false, } export default function (options: Options = {}) { options = { ...defaultOptions, ...options } - const { storeDir, excludes, outputFile } = options as Required + const { storeDir, excludes, outputFile,isDev } = options as Required const storePath = resolve(process.cwd(), storeDir) const outputDir = outputFile.replace(/(\/[^/]*).ts/, '') fs.readdir(outputDir).catch(() => fs.mkdir(outputDir)) @@ -71,10 +73,11 @@ export function useStore(storeName: T) { } generateConfigFiles() - const watcher = chokidar.watch(storePath) - watcher.on('add', () => generateConfigFiles()) - watcher.on('unlink', () => generateConfigFiles()) - + if (process.env.NODE_ENV === 'development' || isDev) { + const watcher = chokidar.watch(storePath) + watcher.on('add', () => generateConfigFiles()) + watcher.on('unlink', () => generateConfigFiles()) + } return { name: 'pinia-auto-refs', }