swc_plugin 0.64.0

SDK for authoring swc plugin
docs.rs failed to build swc_plugin-0.64.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: swc_plugin-0.63.0

SWC Plugin

This crate provides necessary types and macros for creating a custom plugin for SWC (https://swc.rs/), which are WebAssembly modules that may be used to modify behavior of SWC. Currently only transform (https://swc.rs/docs/usage/core#transform) is supported.

Disclaimer: currently SWC plugin support is experimental, there may be possible breaking changes or unexpected behaviors. Please provide issues, feedbacks to https://github.com/swc-project/swc/discussions .

Writing a plugin

All plugin require adding crate-type = ['cdylib'] to the Cargo.toml. For a quick setup, SWC provides a simple commandline to create project for the plugin.

// if you haven't, add build targets for webassembly
rustup target add wasm32-wasi wasm32-unknown-unknown

cargo install swc_cli

swc plugin new ${plugin_name} --target-type wasm32-wasi

When create a new project cli require to specify target type between wasm32-wasi or wasm32-unknown-unknown. wasm32-unknown-unknown will generate slighly smaller binary, but it doesn't support system interfaces as well as macros like printn!().

Generated project will contain a fn with macro #[plugin_transform] which internally does necessary interop for communication between host to the plugin.

There are few references like SWC's jest transform for writing actual VisitMut.