Merge pull request #1328 from alexcrichton/switch-to-web

Switch the `--browser` argument to `--web`
This commit is contained in:
Alex Crichton
2019-03-07 15:25:26 -06:00
committed by GitHub
12 changed files with 71 additions and 46 deletions

View File

@ -4,15 +4,15 @@
[code]: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/without-a-bundler
This example shows how the `--browser` flag can be used load code in a
This example shows how the `--web` flag can be used load code in a
browser directly. For this deployment strategy bundlers like Webpack are not
required. For more information on deployment see the [dedicated
documentation][deployment].
> **Note**: the `--browser` flag is quite new to `wasm-bindgen`, and does not
> **Note**: the `--web` flag is quite new to `wasm-bindgen`, and does not
> currently have support in `wasm-pack` yet. Support will be added soon though!
First let's take a look at the code and see how when we're using `--browser`
First let's take a look at the code and see how when we're using `--web`
we're not actually losing any functionality!
```rust
@ -40,7 +40,7 @@ The older version of using `wasm-bindgen` without a bundler is to use the
`--no-modules` flag to the `wasm-bindgen` CLI. This corresponds to `--target
no-modules` in `wasm-pack`.
While similar to the newer `--browser`, the `--no-modules` flag has a few
While similar to the newer `--web`, the `--no-modules` flag has a few
caveats:
* It does not support [local JS snippets][snippets]

View File

@ -29,11 +29,17 @@ usage of `require` of the generated JS and internally using `require` instead of
ECMAScript modules. When using this flag no further postprocessing (aka a
bundler) should be necessary to work with the wasm.
### `--browser`
For more information about this see the section on [deployment]
This flag will tailor the output specifically for browsers, making it
incompatible with Node. This will basically make the generated JS a tiny bit
smaller as runtime checks for Node won't be necessary.
[deployment]: deployment.html
### `--web`
This flag will generate output suitable for loading natively in browsers today.
The generated JS shims are an ES module which export a `default` instantiation
function, like `--no-modules` below.
For more information about this see the section on [deployment]
### `--no-modules` and `--no-modules-global VAR`
@ -44,8 +50,7 @@ tailored for a properties on the JavaScript global object (e.g. `window`).
The `--no-modules-global VAR` option makes `VAR` the global property that the
JavaScript bindings are attached to.
More information can be found in the [documentation for building without
ECMAScript modules](./no-esm.html).
For more information about this see the section on [deployment]
### `--typescript`
@ -71,3 +76,9 @@ When post-processing the `.wasm` binary, do not demangle Rust symbols in the
When post-processing the `.wasm` binary, do not strip DWARF debug info custom
sections.
### `--browser`
When generating bundler-compatible code (see the section on [deployment]) this
indicates that the bundled code is always intended to go into a browser so a few
checks for Node.js can be elided.

View File

@ -29,17 +29,17 @@ necessary.
If you're not using a bundler but you're still running code in a web browser,
`wasm-bindgen` still supports this! For this use case you'll want to use the
`--browser` flag. You can check out a [full example][nomex] in the
`--web` flag. You can check out a [full example][nomex] in the
documentation, but the highlights of this output are:
* When using `wasm-bindgen` directly you'll pass `--browser`.
* When using `wasm-bindgen` directly you'll pass `--web`.
* The output can natively be included on a web page, and doesn't require any
further postprocessing. The output is included as an ES module.
* The `--browser` mode is not able to use NPM dependencies.
* The `--web` mode is not able to use NPM dependencies.
* You'll want to review the [browser requirements] for `wasm-bindgen` because
no polyfills will be available.
> **Note**: currently `--browser` is not supported in `wasm-pack` because it is
> **Note**: currently `--web` is not supported in `wasm-pack` because it is
> a very recent addition to `wasm-bindgen`, but support will be added soon!
[nomex]: ../examples/without-a-bundler.html
@ -48,7 +48,7 @@ documentation, but the highlights of this output are:
[browser requirements]: browser-support.html
The `wasm-bindgen` CLI also supports an output mode called `--no-modules` which
is similar to `--browser` in that it requires manual initialization of the wasm
is similar to `--web` in that it requires manual initialization of the wasm
and is intended to be included in web pages without any further postprocessing.
See the [without a bundler example][nomex] for some more information about
`--no-modules`, which corresponds to `--target no-modules` in `wasm-pack`.

View File

@ -64,7 +64,7 @@ are important to be aware of. Many of these are temporary though!
this. For now, though, js snippets must be standalone modules and can't import
from anything else.
* Only `--browser` and the default bundler output mode are supported. To support
* Only `--web` and the default bundler output mode are supported. To support
`--nodejs` we'd need to translate ES module syntax to CommonJS (this is
planned to be done, just hasn't been done yet). Additionally to support
`--no-modules` we'd have to similarly translate from ES modules to something