How to compile using your own custom plugin?
I created this discussion (https://github.com/swc-project/swc/discussions/7385) but thought I'd make a post here too to try get a response faster.
I don't understand how I'm supposed to apply custom transformations to a given JavaScript file. I'm using the
swc compile
command (from cargo install swc_cli
), but the transformations aren't applied on the produced output. Even using a config like this with a plugin like https://github.com/williamtetlow/swc-plugin-console-prefix doesn't apply the transformations:
(Input is console.log("world")
, output is console.log("world")
, expected output is console.log("hello", "world")
)
The command I'm running is swc compile in.js --out-file out.js --config-file build.swcrc
. All files including config are in the directory. Enabling env.debug
doesn't produce any helpful output either. The only transformations that get applied are stuff like if I target es5 instead of es2016 (ie const
is turned into var
) as well as the minify
option with mangle
etc. Plugin transformations don't seem to work at all.
Is there a different command you're supposed to use to apply transformations using plugins? I noticed in the README in the mentioned plugin above it uses npx swc ./test.js
but shouldn't you still be able to do the same with the CLI installed with cargo install swc_cli
?GitHub
How do I use my own custom plugin to transform the AST? · swc-proje...
Apologies in advance if this is documented somewhere, I couldn't find it after searching in docs for over an hour. I'm trying to run swc compile in.js --config-file build.swcrc --out-file o...
GitHub
GitHub - williamtetlow/swc-plugin-console-prefix: SWC Transform to ...
SWC Transform to prefix logs. Useful for adding file and line number to logs - GitHub - williamtetlow/swc-plugin-console-prefix: SWC Transform to prefix logs. Useful for adding file and line number...
0 Replies