From dad2d45638436a1166811ee633b640723ea2d68f Mon Sep 17 00:00:00 2001 From: PabloSzx Date: Fri, 19 Mar 2021 00:18:56 -0300 Subject: [PATCH] add ignoreWatch & docs --- docs/README.md | 18 ++++++++++++++++++ src/cli.ts | 1 + src/index.ts | 10 +++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 9560dfff..50eaee2d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -131,6 +131,24 @@ When an entry file like `src/cli.ts` contains hashbang like `#!/bin/env node` ts tsup src/index.ts --watch ``` +You can specify one or more extra folders to ignore watching changes + +> By default it always ignores `dist`, `node_modules` & `.git` + +```bash +tsup src/index.ts --watch --ignore-watch ignore-this-folder +``` + +> You can specify more than a folder repeating "--ignore-watch", for example: `tsup src src/index.ts --watch --ignore-watch folder1 --ignore-watch folder2` + +### onSuccess + +You can specify command to be executed after a successful build, specially useful for **Watch mode** + +``` +tsup src/index.ts --watch --onSuccess "node dist/index.js" +``` + ### Minify output You can also minify the output, resulting into lower bundle sizes by using the `--minify` flag. diff --git a/src/cli.ts b/src/cli.ts index 630f8e0d..d64f374d 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -40,6 +40,7 @@ async function main() { .option('--dts-resolve', 'Resolve externals types used for d.ts files') .option('--sourcemap', 'Generate sourcemap file') .option('--watch', 'Watch mode') + .option('--ignore-watch ', 'Ignore custom paths in watch mode') .option( '--onSuccess ', 'Execute command after successful build, specially useful for watch mode' diff --git a/src/index.ts b/src/index.ts index 4f45fe54..91155308 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,6 +43,7 @@ export type Options = { minifySyntax?: boolean keepNames?: boolean watch?: boolean + ignoreWatch?: string[] | string onSuccess?: string jsxFactory?: string jsxFragment?: string @@ -367,10 +368,17 @@ export async function build(_options: Options) { if (!options.watch) return const { watch } = await import('chokidar') + + const customIgnores = options.ignoreWatch + ? Array.isArray(options.ignoreWatch) + ? options.ignoreWatch + : [options.ignoreWatch] + : [] + const watcher = watch('.', { ignoreInitial: true, ignorePermissionErrors: true, - ignored: ['**/{.git,node_modules}/**', options.outDir], + ignored: ['**/{.git,node_modules}/**', options.outDir, ...customIgnores], }) watcher.on('all', async (type, file) => { console.log(makeLabel('CLI', 'info'), `Change detected: ${type} ${file}`)