swc/examples/usage.rs
강동윤 fcef201695
spack: super-fast bundler (#825)
Version is alpha as it's not complete
2020-06-13 23:09:45 +09:00

33 lines
662 B
Rust

use std::{path::Path, sync::Arc};
use swc::{
self,
common::{
errors::{ColorConfig, Handler},
SourceMap,
},
config::Options,
};
fn main() {
let cm = Arc::<SourceMap>::default();
let handler = Arc::new(Handler::with_tty_emitter(
ColorConfig::Auto,
true,
false,
Some(cm.clone()),
));
let c = swc::Compiler::new(cm.clone(), handler.clone());
let fm = cm
.load_file(Path::new("foo.js"))
.expect("failed to load file");
c.process_js_file(
fm,
&Options {
..Default::default()
},
)
.expect("failed to process file");
}