mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-14 05:21:24 +00:00
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:
4
examples/duck-typed-interfaces/.gitignore
vendored
4
examples/duck-typed-interfaces/.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
package-lock.json
|
||||
rust_duck_typed_interfaces.js
|
||||
rust_duck_typed_interfaces_bg.js
|
||||
rust_duck_typed_interfaces_bg.wasm
|
@ -5,10 +5,8 @@ This directory is an example of using duck-typed JS interfaces with `wasm-bindge
|
||||
You can build and run the example with:
|
||||
|
||||
```
|
||||
$ ./build.sh
|
||||
$ npm run serve
|
||||
```
|
||||
|
||||
(or running the commands on Windows manually)
|
||||
|
||||
and then opening up `http://localhost:8080/` in a web browser should show a
|
||||
smiley face drawn on canvas by Rust and WebAssembly.
|
||||
|
@ -1,15 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
# For more comments about what's going on here, see the `hello_world` example
|
||||
|
||||
set -ex
|
||||
cd "$(dirname $0)"
|
||||
|
||||
cargo build --target wasm32-unknown-unknown
|
||||
|
||||
cargo run --manifest-path ../../crates/cli/Cargo.toml \
|
||||
--bin wasm-bindgen -- \
|
||||
../../target/wasm32-unknown-unknown/debug/rust_duck_typed_interfaces.wasm --out-dir .
|
||||
|
||||
npm install
|
||||
npm run serve
|
@ -1,3 +1,3 @@
|
||||
// For more comments about what's going on here, check out the `hello_world`
|
||||
// example.
|
||||
import('./duck-typed-interfaces');
|
||||
import('./pkg/rust_duck_typed_interfaces');
|
||||
|
@ -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",
|
||||
|
@ -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',
|
||||
@ -9,7 +10,12 @@ module.exports = {
|
||||
filename: 'index.js',
|
||||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin(),
|
||||
new HtmlWebpackPlugin({
|
||||
template: 'index.html'
|
||||
}),
|
||||
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({
|
||||
|
Reference in New Issue
Block a user