@swc/cli
使い方
プリビルドされたバイナリをダウンロードするには、以下を実行してください。
pnpm i -D @swc/cli @swc/core
その後、ファイルをトランスパイルできます。
# Transpile one file and emit to stdout
npx swc ./file.js
# Transpile one file and emit to `output.js`
npx swc ./file.js -o output.js
# Transpile and write to /output dir
npx swc ./my-dir -d output
オプション
--filename (-f)
標準入力から読み込む際に使用するファイル名。これはソースマップとエラーで使用されます。
npx swc -f input.js
--config-file
使用する.swcrc
ファイルへのパス。
npx swc input.js --config-file .swcrc
--env-name
設定とプラグインを読み込む際に使用する「env」の名前。デフォルトではSWC_ENV
の値、またはNODE_ENV
の値、またはdevelopment
です。
npx swc input.js --env-name='test'
--no-swcrc
.swcrc
ファイルを検索するかどうか。
npx swc input.js --no-swcrc
--ignore
コンパイル**しない**グロブパスのリスト。
npx swc src --ignore **/*.test.js
--only
コンパイル**のみ**を行うグロブパスのリスト
例
npx swc src --only **/*.js
--watch (-w)
変更時にファイルを自動的に再コンパイルするには、chokidar
をインストールしてください。
npm i -D chokidar
次に、-w
フラグを追加します。
npx swc input.js -w
--quiet (-q)
コンパイル出力を抑制します。
npx swc input.js -q
--source-maps (-s)
値: true|false|inline|both
npx swc input.js -s
--source-map-target
ソースマップのfile
を定義します。
npx swc input.js -s --source-map-target input.map.js
--source-file-name
返されたソースマップでsources[0]
を設定します。
--source-root
すべてのソースが相対的となるルート。
--out-file (-o)
すべての入力ファイルを単一のファイルにコンパイルします。
npx swc input.js -o output.js
--out-dir (-d)
モジュールの入力ディレクトリを出力ディレクトリにコンパイルします。
npx swc src -d dist
--copy-files (-D)
ディレクトリをコンパイルするときに、コンパイル不可能なファイルをコピーします。
npx swc src --copy-files
--include-dotfiles
コンパイルおよびコンパイル不可能なファイルのコピー時にドットファイルを含めます。
npx swc src --include-dotfiles
--config (-C)
.swcrc
ファイルから設定を上書きします。
npx swc src -C module.type=amd -C module.moduleId=hello
--sync
swcを同期的に呼び出します。デバッグに役立ちます。
npx swc src --sync
--log-watch-compilation
監視対象ファイルが正常にコンパイルされたときにメッセージをログに記録します。
npx swc input.js --log-watch-compilation
--extensions
特定の拡張子を使用します。
--strip-leading-paths
最終的な出力パスを作成する際に、先頭のディレクトリ(すべての親相対パスを含む)を削除します。例として、src
フォルダーの下のすべてのモジュールをdist
フォルダーにコンパイルし、dist
の中にsrc
フォルダーを作成せずにコンパイルします。
npx swc src -d dist --strip-leading-paths