diff --git a/src/bindgen.rs b/src/bindgen.rs index 5df25f4..83c615a 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -32,7 +32,7 @@ pub fn wasm_bindgen_build( path: &str, name: &str, disable_dts: bool, - nodejs: bool, + target: String, ) -> Result<(), Error> { let step = format!( "{} {}Running WASM-bindgen...", @@ -49,7 +49,10 @@ pub fn wasm_bindgen_build( "--no-typescript" }; - let nodejs_arg = if nodejs { "--nodejs" } else { "" }; + let target_arg = match target.as_str() { + "nodejs" => "--nodejs", + _ => "--browser", + }; let output = Command::new("wasm-bindgen") .current_dir(path) @@ -57,7 +60,7 @@ pub fn wasm_bindgen_build( .arg("--out-dir") .arg("./pkg") .arg(dts_arg) - .arg(nodejs_arg) + .arg(target_arg) .output()?; pb.finish(); if !output.status.success() { diff --git a/src/command.rs b/src/command.rs index d5f262b..551f380 100644 --- a/src/command.rs +++ b/src/command.rs @@ -28,11 +28,9 @@ pub enum Command { /// this flag will disable generating this TypeScript file. disable_dts: bool, - #[structopt(long = "nodejs")] - /// This flag will tailor output for Node instead of browsers, allowing - /// for native usage of require of the generated JS and internally using - /// require instead of ES modules. - nodejs: bool, + #[structopt(long = "target", short = "t", default_value = "browser")] + /// Sets the target environment. [possible values: browser, nodejs] + target: String, }, #[structopt(name = "pack")] @@ -84,8 +82,8 @@ pub fn run_wasm_pack(command: Command) -> result::Result<(), Error> { path, scope, disable_dts, - nodejs, - } => init(path, scope, disable_dts, nodejs), + target, + } => init(path, scope, disable_dts, target), Command::Pack { path } => pack(path), Command::Publish { path } => publish(path), Command::Login { @@ -132,7 +130,7 @@ fn init( path: Option<String>, scope: Option<String>, disable_dts: bool, - nodejs: bool, + target: String, ) -> result::Result<(), Error> { let started = Instant::now(); @@ -145,7 +143,7 @@ fn init( readme::copy_from_crate(&crate_path)?; bindgen::cargo_install_wasm_bindgen()?; let name = manifest::get_crate_name(&crate_path)?; - bindgen::wasm_bindgen_build(&crate_path, &name, disable_dts, nodejs)?; + bindgen::wasm_bindgen_build(&crate_path, &name, disable_dts, target)?; PBAR.message(&format!( "{} Done in {}", emoji::SPARKLE,