From 142e62e711d627c8dd0f2419a43b1c8b822298a3 Mon Sep 17 00:00:00 2001 From: lake2 Date: Fri, 13 Sep 2024 15:25:28 +0800 Subject: [PATCH] Update cli.mdx --- pages/docs/usage/cli.mdx | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/pages/docs/usage/cli.mdx b/pages/docs/usage/cli.mdx index 0a7f083a..d11478ca 100644 --- a/pages/docs/usage/cli.mdx +++ b/pages/docs/usage/cli.mdx @@ -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. + + + + + + + + + + + + + + + + +