@swc/cli
Usage
Run the following to download pre-built binaries:
Then, you can transpile your files:
Flow input
To compile Flow code with the CLI, point swc at a .swcrc file that sets
jsc.parser.syntax to "flow":
For JSX-flavored Flow files, set jsx: true and compile .jsx inputs with the
same config. See the Flow guide for the full list of parser
options.
Options
--filename (-f)
Filename to use when reading from stdin. This will be used in source maps and errors.
--config-file
Path to a .swcrc file to use.
--env-name
The name of the 'env' to use when loading configs and plugins. Defaults to the value of SWC_ENV, or else NODE_ENV, or else development.
--no-swcrc
Whether or not to look up .swcrc files.
--ignore
List of glob paths to not compile.
--only
List of glob paths to only compile
Example:
--watch (-w)
To automatically recompile files on changes, install chokidar:
Then, add the -w flag:
--quiet (-q)
Suppress compilation output.
--source-maps (-s)
Values: true|false|inline|both
--source-map-target
Define the file for the source map.
--source-file-name
Set sources[0] on returned source map
--source-root
The root from which all sources are relative.
--out-file (-o)
Compile all input files into a single file.
--out-dir (-d)
Compile an input directory of modules into an output directory.
--copy-files (-D)
When compiling a directory, copy over non-compilable files.
--include-dotfiles
Include dotfiles when compiling and copying non-compilable files.
--config (-C)
Override a config from .swcrc file.
--sync
Invoke swc synchronously. Useful for debugging.
--log-watch-compilation
Log a message when a watched file is successfully compiled.
--extensions
Use specific extensions.
--strip-leading-paths
Remove the leading directory (including all parent relative paths) when building the final output path. As an example it compiles all modules under src folder to dist folder, without create the src folder inside of dist.
use in nodejs script
Please note that when using callbacks, the --quiet (-q) will always be true.
--out-file-extension
Use a specific extension for the output files.
As an example, if you want to render your es6 output to .mjs file extensions, you could call:
Please note that if you are compiling multiple files, you will also need to make sure that your imports are resolved with the appropriate
extension. You can do so by making use of the resolveFully and outFileExtension module options:
