SWC API
Rspack uses SWC under the hood to transform and minify JavaScript code, and experimentally exposes some SWC JavaScript APIs through rspack.experiments.swc. This allows you to directly call SWC methods like transform or minify without installing the additional @swc/core package.
Examples
Here is a simple example demonstrating how to transform JavaScript code using Rspack:
In addition to using the swc API directly, you can also use it in loaders or plugins to help with code transform or minify.
my-loader.mjs
my-plugin.mjs
Options
The API options accepted by the above APIs are passed to SWC.
You can learn more about configuration options in the SWC official documentation:
- SWC Transform API - Code transform options
- SWC Minify API - Code minify options

