diff --git a/src/bin.ts b/src/bin.ts index abe42cc..8df7538 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -115,6 +115,7 @@ type DevOptions = { clear: boolean cls: boolean 'ignore-watch': string + debounce: string 'all-deps': boolean 'deps-level': string 'compile-timeout': string diff --git a/src/index.ts b/src/index.ts index ed1be9c..6d7922a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -228,7 +228,17 @@ export const runDev = ( } } + let debounceTimeout: ReturnType + const defaultDebounce: string = (opts.debounce === '') ? '1000' : opts.debounce + const debounceTime: number = parseInt(defaultDebounce, 10) || 0 function restart(file: string, isManualRestart?: boolean) { + clearTimeout(debounceTimeout) + debounceTimeout = setTimeout(() => { + restartAfterDebounce(file, isManualRestart) + }, debounceTime) + } + + function restartAfterDebounce(file: string, isManualRestart?: boolean) { if (file === compiler.tsConfigPath) { notify('Reinitializing TS compilation', '') compiler.init()