-
I want to pass parameters to a custom swc-plugin to dynamically replace the value of a variable. How do I do this? const swc = require("@swc/core");
const fs = require("fs");
const srcCode = `const a = 1;`;
swc.transform(srcCode, {
"jsc": {
"parser": {
"syntax": "ecmascript"
},
"target": "es2015",
"experimental": {
"plugins": [
["/Users/chenwenliang/formal_project/baidu/personal-code/swc-plugin/target/wasm32-wasi/release/const_replace.wasm",{}],
]
}
},
"minify": false
}
)
.then((result) => {
console.log(result.code);
})
.catch((err) => {
console.error(err);
}); |
Beta Was this translation helpful? Give feedback.
Answered by
kdy1
Jul 5, 2024
Replies: 1 comment 2 replies
-
{} after the path to Wasm file is the config object passed to the plugin. See https://github.com/swc-project/plugins/blob/main/packages/styled-jsx/src/lib.rs#L13 for example of getting the config from Wasm plugin |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
chenwll
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
{} after the path to Wasm file is the config object passed to the plugin.
See https://github.com/swc-project/plugins/blob/main/packages/styled-jsx/src/lib.rs#L13 for example of getting the config from Wasm plugin