这是indexloc提供的服务,不要输入任何密码
Skip to content

add ignoreWatch & docs #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path>', 'Ignore custom paths in watch mode')
.option(
'--onSuccess <command>',
'Execute command after successful build, specially useful for watch mode'
Expand Down
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type Options = {
minifySyntax?: boolean
keepNames?: boolean
watch?: boolean
ignoreWatch?: string[] | string
onSuccess?: string
jsxFactory?: string
jsxFragment?: string
Expand Down Expand Up @@ -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}`)
Expand Down