Skip to content
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

add callbacks #261

Merged
merged 1 commit into from
Oct 7, 2024
Merged
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
54 changes: 54 additions & 0 deletions pages/docs/usage/cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,57 @@ Remove the leading directory (including all parent relative paths) when building
```sh
npx swc src -d dist --strip-leading-paths
```

## use in nodejs script
```js
const { swcDir } = require('@swc/cli');

const swcOptions = {
jsc: {
target: 'esnext',
externalHelpers: true,
},
module: {
type: 'commonjs',
},
sourceMaps: true,
};

swcDir({
cliOptions: {
outDir: './dist',
watch: true,
filenames: ['./src'],
extensions: ['.ts'],
stripLeadingPaths: true,
},
swcOptions,
callbacks: {
onSuccess: e => {
console.log(e);
},
onFail: e => {
console.log(e);
},
onWatchReady: () => {},
},
});
```
Please note that when using `callbacks`, the `--quiet (-q)` will always be true.