Convert all examples to using wasm-pack

This commit migrates all our examples to using `wasm-pack build` to
compile their code and run `wasm-bindgen`. This should make it a bit
easier to understand the examples as there's less to follow during the
build step.

Webpack projects are all using `@wasm-tool/wasm-pack-plugin` as well so
the build step is simple `npm run serve`. Other examples which retain
`build.sh` are just using `wasm-pack build` now
This commit is contained in:
Alex Crichton
2019-01-08 15:14:15 -08:00
parent d79ca22234
commit 32c611d16d
126 changed files with 180 additions and 481 deletions

View File

@ -1,4 +0,0 @@
fetch.d.ts
fetch.js
fetch_bg.wasm
package-lock.json

View File

@ -9,10 +9,7 @@ online][compiled]
You can build the example locally with:
```
$ ./build.sh
$ npm run serve
```
(or running the commands on Windows manually)
and then visiting http://localhost:8080 in a browser should run the example!

View File

@ -1,13 +0,0 @@
#!/bin/sh
# For more comments about what's going on here, see the `hello_world` example
set -ex
cargo build --target wasm32-unknown-unknown
cargo run --manifest-path ../../crates/cli/Cargo.toml \
--bin wasm-bindgen -- \
../../target/wasm32-unknown-unknown/debug/fetch.wasm --out-dir .
npm install
npm run serve

View File

@ -1,8 +1,8 @@
const rust = import('./fetch');
const rust = import('./pkg/fetch');
rust
.then(m => {
m.run().then((data) => {
return m.run().then((data) => {
console.log(data);
console.log("The latest commit to the wasm-bindgen %s branch is:", data.name);

View File

@ -4,6 +4,7 @@
"serve": "webpack-dev-server"
},
"devDependencies": {
"@wasm-tool/wasm-pack-plugin": "0.2.1",
"text-encoding": "^0.7.0",
"html-webpack-plugin": "^3.2.0",
"webpack": "^4.11.1",

View File

@ -1,6 +1,7 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin");
module.exports = {
entry: './index.js',
@ -10,6 +11,9 @@ module.exports = {
},
plugins: [
new HtmlWebpackPlugin(),
new WasmPackPlugin({
crateDirectory: path.resolve(__dirname, ".")
}),
// Have this example work in Edge which doesn't ship `TextEncoder` or
// `TextDecoder` at this time.
new webpack.ProvidePlugin({