Introducing experimental native SWC CLI #3859
Replies: 6 comments 9 replies
-
when I try |
Beta Was this translation helpful? Give feedback.
-
This is great news @kwonoj. Would it be possible for this project to package the raw binary |
Beta Was this translation helpful? Give feedback.
-
👍 This will also simplify adoption in linux distros – packaging swc. I’m working on Alpine Linux package right now. |
Beta Was this translation helpful? Give feedback.
-
@kwonoj Minification does not seem to be working when using the native CLI. Tested with latest version 1.3.21 of # Node-based CLI -- minification works
node swc.js --filename input.ts --config minify=true --config sourceMaps=false
# Native CLI -- minification seems to be ignored
swc.exe compile --filename input.ts --config minify=true --config sourceMaps=false |
Beta Was this translation helpful? Give feedback.
-
The --source-maps option was added in #6708. |
Beta Was this translation helpful? Give feedback.
-
FYI the latest release is good enough for Bazel (via https://github.com/aspect-build/rules_swc) to switch over to |
Beta Was this translation helpful? Give feedback.
-
Introduction
SWC currently provides its cli package
@swc/cli
. It is a wrapping node.js script to core node.js binding@swc/node
. It is quite a common pattern to build CLI on top of the library we are offering, which also allows us to share core library to the application. However, it means every CLI invocation need to spend some time towarm up
node.js process. Moreover, while SWC itself is agnostic to any javascript runtime, cli requires to install node.js as a dependency We spent some time writing a native CLI binary for SWC to attempt to resolve those. While it only supports very basic features I'd like to share it and would like to welcome any contributions.Installation
Please note distribution needs more thought for actual release.
There are 2 ways to use new cli currently. First, if you have
cargo
installed you can install it viaOr if you have node.js with npm or other package manager you can install it via
Npm package's binary name is
swcx
. It is to avoid to conflict existing@swc/cli
's binary entryswc
. I expect it'll likely change with proper distribution later.Using CLI
There is one major difference between
@swc/cli
and new binary. Previouslyswc
was an entrypoint to SWC's compilation (transform). New CLI tries to consolidates all of the features of SWC with its subcommand.Option questions
It is early stage of development and there are lot of open questions need to be resolved.
@swc/core
ships cli by default, or should be installed separately via@swc/cli
?How to contribute
We welcome any contribution to improve, implement the remaining SWC CLI features. If you'd like to dive in, please check these.
execute
fn for new features, or fix (https://github.com/swc-project/swc/blob/main/crates/swc_cli/src/commands/plugin.rs#L120)For
compile
subcommand, there is a predefined option from existing@swc/cli
we need to port over (https://github.com/swc-project/swc/blob/main/crates/swc_cli/src/commands/compile.rs#L24). For other subcommands that is not fully determined yet, please suggest a proposal at https://github.com/swc-project/swc/discussions before making an actual implementation PR. We hope to make CLI's public interface to stay long without major breaking changes and want to start from minimal set of features.FAQ
@swc/cli
? : Eventually yes. However, we'll make an official announcement when it's ready. Until then@swc/cli
will not be deprecated.npx swcx
still invokes node.js, isn't it?: Yes. We'll need to sort out how to distribute binary, while having linkednode_modules/.bin
will exist to easier access from npm ecosystem.Beta Was this translation helpful? Give feedback.
All reactions