Function esbuild_rs::transform [−][src]
pub fn transform(
code: Arc<Vec<u8>>,
options: Arc<TransformOptions>
) -> TransformFutureⓘNotable traits for TransformFutureimpl Future for TransformFuture type Output = TransformResult;
Expand description
Future wrapper for transform_direct
.
Arguments
code
- Source code to transform. Must be UTF-8. A reference will be held on the Arc until the Future completes.options
- Built TransformOptions created from a TransformOptionsBuilder. A reference will be held on the Arc until the Future completes.
Examples
This example uses the async-std async runtime.
use std::sync::Arc;
use async_std::task;
use esbuild_rs::{TransformOptionsBuilder, transform, TransformResult};
fn main() {
let src = Arc::new(b"let x = NAME;".to_vec());
let mut options_builder = TransformOptionsBuilder::new();
options_builder.define.insert("NAME".to_string(), "world".to_string());
let options = options_builder.build();
let res = task::block_on(transform(src, options));
assert_eq!(res.code.as_str(), "let x = world;\n");
}