mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 12:31:22 +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/fetch/.gitignore
vendored
4
examples/fetch/.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
fetch.d.ts
|
||||
fetch.js
|
||||
fetch_bg.wasm
|
||||
package-lock.json
|
@ -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!
|
||||
|
||||
|
@ -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
|
@ -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);
|
||||
|
@ -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',
|
||||
@ -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({
|
||||
|
Reference in New Issue
Block a user