Skip to content

Commit

Permalink
fix: build mode watch file
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen-1998 committed Nov 14, 2023
1 parent a06fb41 commit 9933541
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Options>
const { storeDir, excludes, outputFile,isDev } = options as Required<Options>
const storePath = resolve(process.cwd(), storeDir)
const outputDir = outputFile.replace(/(\/[^/]*).ts/, '')
fs.readdir(outputDir).catch(() => fs.mkdir(outputDir))
Expand Down Expand Up @@ -71,10 +73,11 @@ export function useStore<T extends keyof typeof storeExports>(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',
}
Expand Down

0 comments on commit 9933541

Please sign in to comment.