mirror of
https://github.com/egoist/tsup.git
synced 2025-12-08 20:35:58 +00:00
fix: use chokidar to watch files again
This commit is contained in:
parent
508b6284f0
commit
70cf288df8
21
src/index.ts
21
src/index.ts
@ -14,7 +14,7 @@ import {
|
||||
removeFiles,
|
||||
} from './utils'
|
||||
import glob from 'globby'
|
||||
import { PrettyError } from './errors'
|
||||
import { handleError, PrettyError } from './errors'
|
||||
import { postcssPlugin } from './esbuild/postcss'
|
||||
import { externalPlugin } from './esbuild/external'
|
||||
import { sveltePlugin } from './esbuild/svelte'
|
||||
@ -182,7 +182,7 @@ export async function runEsbuild(
|
||||
minifyIdentifiers: options.minifyIdentifiers,
|
||||
minifySyntax: options.minifySyntax,
|
||||
keepNames: options.keepNames,
|
||||
watch: options.watch,
|
||||
incremental: options.watch,
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(`${makeLabel(format, 'error')} Build failed`)
|
||||
@ -362,10 +362,27 @@ export async function build(_options: Options) {
|
||||
}
|
||||
}
|
||||
|
||||
const startWatcher = async () => {
|
||||
if (!options.watch) return
|
||||
|
||||
const { watch } = await import('chokidar')
|
||||
const watcher = watch('.', {
|
||||
ignoreInitial: true,
|
||||
ignorePermissionErrors: true,
|
||||
ignored: ['**/{.git,node_modules}/**', options.outDir],
|
||||
})
|
||||
watcher.on('all', async (type, file) => {
|
||||
console.log(makeLabel('CLI', 'info'), `Change detected: ${type} ${file}`)
|
||||
await buildAll().catch(handleError)
|
||||
})
|
||||
}
|
||||
|
||||
console.log(makeLabel('CLI', 'info'), `Target: ${options.target}`)
|
||||
|
||||
await buildAll()
|
||||
|
||||
startWatcher()
|
||||
|
||||
if (options.dts) {
|
||||
const hasTypescript = resolveFrom.silent(process.cwd(), 'typescript')
|
||||
if (!hasTypescript) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user