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,
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() {

@ -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,

Loading…
Cancel
Save