-
I have some basic starter Rust code (see below) and my goal is to write a plugin in Rust (to visit JS functions) without needing to compile it to WASM. Is that possible? And if so, how can I do it? Or is that not advisable? Any help would be appreciated! Thank you! Current Rust Codeuse std::{path::Path, sync::Arc};
use swc::config::Options;
use swc_common::{
errors::{ColorConfig, Handler},
SourceMap,
GLOBALS,
};
fn main() {
let cm = Arc::<SourceMap>::default();
let handler = Arc::new(Handler::with_tty_emitter(
ColorConfig::Auto,
true,
false,
Some(cm.clone()),
));
let compiler = swc::Compiler::new(cm.clone());
let fm = cm
.load_file(Path::new("sample.in.js"))
.expect("failed to load file");
let res = GLOBALS.set(&Default::default(), || {
compiler.process_js_file(
fm.clone(),
&handler,
&Options {
..Default::default()
},
)
})
.expect("failed to process file");
std::fs::write("sample.out.js", res.code).expect("failed to write file");
} |
Beta Was this translation helpful? Give feedback.
Answered by
kwonoj
Oct 1, 2023
Replies: 1 comment 1 reply
-
Swc does not support to execute native rust code as plugins. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
a-poor
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Swc does not support to execute native rust code as plugins.