use target flag with browser and nodejs values

master
Jan Willem Henckel 7 years ago committed by Ashley Williams
parent 7f8740a394
commit fa77bb5d9d
  1. 9
      src/bindgen.rs
  2. 16
      src/command.rs

@ -32,7 +32,7 @@ pub fn wasm_bindgen_build(
path: &str, path: &str,
name: &str, name: &str,
disable_dts: bool, disable_dts: bool,
nodejs: bool, target: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
let step = format!( let step = format!(
"{} {}Running WASM-bindgen...", "{} {}Running WASM-bindgen...",
@ -49,7 +49,10 @@ pub fn wasm_bindgen_build(
"--no-typescript" "--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") let output = Command::new("wasm-bindgen")
.current_dir(path) .current_dir(path)
@ -57,7 +60,7 @@ pub fn wasm_bindgen_build(
.arg("--out-dir") .arg("--out-dir")
.arg("./pkg") .arg("./pkg")
.arg(dts_arg) .arg(dts_arg)
.arg(nodejs_arg) .arg(target_arg)
.output()?; .output()?;
pb.finish(); pb.finish();
if !output.status.success() { if !output.status.success() {

@ -28,11 +28,9 @@ pub enum Command {
/// this flag will disable generating this TypeScript file. /// this flag will disable generating this TypeScript file.
disable_dts: bool, disable_dts: bool,
#[structopt(long = "nodejs")] #[structopt(long = "target", short = "t", default_value = "browser")]
/// This flag will tailor output for Node instead of browsers, allowing /// Sets the target environment. [possible values: browser, nodejs]
/// for native usage of require of the generated JS and internally using target: String,
/// require instead of ES modules.
nodejs: bool,
}, },
#[structopt(name = "pack")] #[structopt(name = "pack")]
@ -84,8 +82,8 @@ pub fn run_wasm_pack(command: Command) -> result::Result<(), Error> {
path, path,
scope, scope,
disable_dts, disable_dts,
nodejs, target,
} => init(path, scope, disable_dts, nodejs), } => init(path, scope, disable_dts, target),
Command::Pack { path } => pack(path), Command::Pack { path } => pack(path),
Command::Publish { path } => publish(path), Command::Publish { path } => publish(path),
Command::Login { Command::Login {
@ -132,7 +130,7 @@ fn init(
path: Option<String>, path: Option<String>,
scope: Option<String>, scope: Option<String>,
disable_dts: bool, disable_dts: bool,
nodejs: bool, target: String,
) -> result::Result<(), Error> { ) -> result::Result<(), Error> {
let started = Instant::now(); let started = Instant::now();
@ -145,7 +143,7 @@ fn init(
readme::copy_from_crate(&crate_path)?; readme::copy_from_crate(&crate_path)?;
bindgen::cargo_install_wasm_bindgen()?; bindgen::cargo_install_wasm_bindgen()?;
let name = manifest::get_crate_name(&crate_path)?; 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!( PBAR.message(&format!(
"{} Done in {}", "{} Done in {}",
emoji::SPARKLE, emoji::SPARKLE,

Loading…
Cancel
Save