Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn wasm_bindgen_build(
disable_dts: bool,
weak_refs: bool,
reference_types: bool,
browser_only: bool,
target: Target,
profile: BuildProfile,
extra_options: &Vec<String>,
Expand Down Expand Up @@ -70,6 +71,13 @@ pub fn wasm_bindgen_build(
let target_arg = build_target_arg(target, &bindgen_path)?;
if supports_dash_dash_target(&bindgen_path)? {
cmd.arg("--target").arg(target_arg);
if browser_only {
if let Target::Bundler = target {
cmd.arg("--browser");
} else {
bail!("You can only specify `--browser` when building for the 'bundler' target.")
}
}
} else {
cmd.arg(target_arg);
}
Expand Down
9 changes: 9 additions & 0 deletions src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct Build {
pub disable_dts: bool,
pub weak_refs: bool,
pub reference_types: bool,
pub browser_only: bool,
pub target: Target,
pub no_pack: bool,
pub no_opt: bool,
Expand Down Expand Up @@ -139,6 +140,11 @@ pub struct BuildOptions {
/// Enable usage of WebAssembly reference types.
pub reference_types: bool,

#[clap(long = "browser")]
/// Hint that the generated JS should only be compatible with a browser.
/// Only supported when using the 'bundler' target.
pub browser_only: bool,

#[clap(long = "target", short = 't', default_value = "bundler")]
/// Sets the target environment. [possible values: bundler, nodejs, web, no-modules, deno]
pub target: Target,
Expand Down Expand Up @@ -189,6 +195,7 @@ impl Default for BuildOptions {
disable_dts: false,
weak_refs: false,
reference_types: false,
browser_only: false,
target: Target::default(),
debug: false,
dev: false,
Expand Down Expand Up @@ -237,6 +244,7 @@ impl Build {
disable_dts: build_opts.disable_dts,
weak_refs: build_opts.weak_refs,
reference_types: build_opts.reference_types,
browser_only: build_opts.browser_only,
target: build_opts.target,
no_pack: build_opts.no_pack,
no_opt: build_opts.no_opt,
Expand Down Expand Up @@ -429,6 +437,7 @@ impl Build {
self.disable_dts,
self.weak_refs,
self.reference_types,
self.browser_only,
self.target,
self.profile,
&self.extra_options,
Expand Down