diff --git a/.travis.yml b/.travis.yml index 3f1a7fb2..03919240 100644 --- a/.travis.yml +++ b/.travis.yml @@ -93,14 +93,15 @@ matrix: - *INSTALL_NODE_VIA_NVM - *INSTALL_AWS - npm install + - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f script: + - cargo build -p wasm-bindgen-cli + - ln -snf target/debug/wasm-bindgen $HOME/.cargo/wasm-bindgen - | for dir in `ls examples | grep -v README | grep -v asm.js | grep -v raytrace | grep -v no_modules`; do (cd examples/$dir && - sed -i "s|: \"webpack-dev-server\"|: \"webpack --output-path $HOME/$TRAVIS_BUILD_NUMBER/exbuild/$dir\"|" package.json && - sed -i 's/npm install//' build.sh && ln -fs ../../node_modules . && - ./build.sh) || exit 1; + npm run build -- --output-path $HOME/$TRAVIS_BUILD_NUMBER/exbuild/$dir) || exit 1; done - if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then aws s3 sync --quiet ~/$TRAVIS_BUILD_NUMBER s3://wasm-bindgen-ci/$TRAVIS_BUILD_NUMBER; fi if: branch = master diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 00000000..20fec396 --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1,4 @@ +package-lock.json +pkg +dist +wasm-pack.log diff --git a/examples/add/.gitignore b/examples/add/.gitignore deleted file mode 100644 index bdaab9c5..00000000 --- a/examples/add/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -package-lock.json -add.js -add_bg.wasm diff --git a/examples/add/README.md b/examples/add/README.md index 57c508e8..a72caf3c 100644 --- a/examples/add/README.md +++ b/examples/add/README.md @@ -9,9 +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! diff --git a/examples/add/build.sh b/examples/add/build.sh deleted file mode 100755 index 8d2dd6e8..00000000 --- a/examples/add/build.sh +++ /dev/null @@ -1,12 +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 --release -cargo run --manifest-path ../../crates/cli/Cargo.toml \ - --bin wasm-bindgen -- \ - ../../target/wasm32-unknown-unknown/release/add.wasm --out-dir . -npm install -npm run serve diff --git a/examples/add/index.js b/examples/add/index.js index bef9fbcc..e8f52450 100644 --- a/examples/add/index.js +++ b/examples/add/index.js @@ -1,6 +1,6 @@ // For more comments about what's going on here, check out the `hello_world` // example -const rust = import('./add'); +const rust = import('./pkg/add'); rust .then(m => alert('1 + 2 = ' + m.add(1, 2))) .catch(console.error); diff --git a/examples/add/package.json b/examples/add/package.json index 806119cd..49198ff2 100644 --- a/examples/add/package.json +++ b/examples/add/package.json @@ -1,9 +1,10 @@ { "scripts": { - "build": "webpack", - "serve": "webpack-dev-server" + "build": "webpack -p", + "serve": "webpack-dev-server -p" }, "devDependencies": { + "@wasm-tool/wasm-pack-plugin": "0.2.1", "text-encoding": "^0.7.0", "html-webpack-plugin": "^3.2.0", "webpack": "^4.11.1", diff --git a/examples/add/webpack.config.js b/examples/add/webpack.config.js index 53396f30..a6f6e1e9 100644 --- a/examples/add/webpack.config.js +++ b/examples/add/webpack.config.js @@ -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({ diff --git a/examples/canvas/.gitignore b/examples/canvas/.gitignore deleted file mode 100644 index a5e6169e..00000000 --- a/examples/canvas/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -package-lock.json -canvas.js -canvas_bg.js -canvas_bg.wasm diff --git a/examples/canvas/README.md b/examples/canvas/README.md index 2ab89e80..bbd03128 100644 --- a/examples/canvas/README.md +++ b/examples/canvas/README.md @@ -9,9 +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! diff --git a/examples/canvas/build.sh b/examples/canvas/build.sh deleted file mode 100755 index 0198ef80..00000000 --- a/examples/canvas/build.sh +++ /dev/null @@ -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/canvas.wasm --out-dir . - -npm install -npm run serve diff --git a/examples/canvas/index.js b/examples/canvas/index.js index 4b586d9a..a649b473 100644 --- a/examples/canvas/index.js +++ b/examples/canvas/index.js @@ -1,4 +1,4 @@ // For more comments about what's going on here, check out the `hello_world` // example. -import('./canvas') +import('./pkg/canvas') .catch(console.error); diff --git a/examples/canvas/package.json b/examples/canvas/package.json index 806119cd..9fafb189 100644 --- a/examples/canvas/package.json +++ b/examples/canvas/package.json @@ -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", diff --git a/examples/canvas/webpack.config.js b/examples/canvas/webpack.config.js index f15dc6b5..25afd180 100644 --- a/examples/canvas/webpack.config.js +++ b/examples/canvas/webpack.config.js @@ -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,7 +11,10 @@ module.exports = { }, plugins: [ new HtmlWebpackPlugin({ - template: "index.html" + 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. diff --git a/examples/char/.gitignore b/examples/char/.gitignore deleted file mode 100644 index 937451e4..00000000 --- a/examples/char/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -package-lock.json -char.js -char_bg.js -char_bg.wasm diff --git a/examples/char/README.md b/examples/char/README.md index 884d9a62..4f0ec173 100644 --- a/examples/char/README.md +++ b/examples/char/README.md @@ -9,9 +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! diff --git a/examples/char/build.sh b/examples/char/build.sh deleted file mode 100755 index 7e4aa2f1..00000000 --- a/examples/char/build.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -set -ex - -# Build the `hello_world.wasm` file using Cargo/rustc -cargo build --target wasm32-unknown-unknown - -# Run the `wasm-bindgen` CLI tool to postprocess the wasm file emitted by the -# Rust compiler to emit the JS support glue that's necessary -# -# Here we're using the version of the CLI in this repository, but for external -# usage you'd use the commented out version below -cargo run --manifest-path ../../crates/cli/Cargo.toml \ - --bin wasm-bindgen -- \ - ../../target/wasm32-unknown-unknown/debug/char.wasm --out-dir . -# wasm-bindgen ../../target/wasm32-unknown-unknown/hello_world.wasm --out-dir . - -# Finally, package everything up using Webpack and start a server so we can -# browse the result - -npm install -npm run serve diff --git a/examples/char/index.js b/examples/char/index.js index c1d0f4f5..caa92b42 100644 --- a/examples/char/index.js +++ b/examples/char/index.js @@ -1,6 +1,6 @@ /* eslint-disable no-unused-vars */ import { chars } from './chars-list.js'; -let imp = import('./char.js'); +let imp = import('./pkg/char'); let mod; let counters = []; diff --git a/examples/char/package.json b/examples/char/package.json index 806119cd..9fafb189 100644 --- a/examples/char/package.json +++ b/examples/char/package.json @@ -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", diff --git a/examples/char/webpack.config.js b/examples/char/webpack.config.js index f15dc6b5..353fbcaf 100644 --- a/examples/char/webpack.config.js +++ b/examples/char/webpack.config.js @@ -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', @@ -12,6 +13,9 @@ module.exports = { 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({ diff --git a/examples/closures/.gitignore b/examples/closures/.gitignore deleted file mode 100644 index 3e0dcd94..00000000 --- a/examples/closures/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -package-lock.json -closures.js -closures_bg.js -closures_bg.wasm diff --git a/examples/closures/README.md b/examples/closures/README.md index 5782c28a..ddf70171 100644 --- a/examples/closures/README.md +++ b/examples/closures/README.md @@ -9,9 +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! diff --git a/examples/closures/build.sh b/examples/closures/build.sh deleted file mode 100755 index 9ed029a9..00000000 --- a/examples/closures/build.sh +++ /dev/null @@ -1,12 +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/closures.wasm --out-dir . -npm install -npm run serve diff --git a/examples/closures/index.js b/examples/closures/index.js index cc27e057..5fb5aa35 100644 --- a/examples/closures/index.js +++ b/examples/closures/index.js @@ -1,4 +1,4 @@ // For more comments about what's going on here, check out the `hello_world` // example -import('./closures') +import('./pkg/closures') .catch(console.error); diff --git a/examples/closures/package.json b/examples/closures/package.json index 806119cd..9fafb189 100644 --- a/examples/closures/package.json +++ b/examples/closures/package.json @@ -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", diff --git a/examples/closures/webpack.config.js b/examples/closures/webpack.config.js index f15dc6b5..a6f6e1e9 100644 --- a/examples/closures/webpack.config.js +++ b/examples/closures/webpack.config.js @@ -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,8 +10,9 @@ module.exports = { filename: 'index.js', }, plugins: [ - new HtmlWebpackPlugin({ - template: "index.html" + new HtmlWebpackPlugin(), + new WasmPackPlugin({ + crateDirectory: path.resolve(__dirname, ".") }), // Have this example work in Edge which doesn't ship `TextEncoder` or // `TextDecoder` at this time. diff --git a/examples/console_log/.gitignore b/examples/console_log/.gitignore deleted file mode 100644 index 4fd1390e..00000000 --- a/examples/console_log/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -package-lock.json -console_log.js -console_log_bg.js -console_log_bg.wasm diff --git a/examples/console_log/README.md b/examples/console_log/README.md index c72b418c..32fa8d49 100644 --- a/examples/console_log/README.md +++ b/examples/console_log/README.md @@ -9,9 +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! diff --git a/examples/console_log/build.sh b/examples/console_log/build.sh deleted file mode 100755 index f2594d41..00000000 --- a/examples/console_log/build.sh +++ /dev/null @@ -1,12 +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/console_log.wasm --out-dir . -npm install -npm run serve diff --git a/examples/console_log/index.js b/examples/console_log/index.js index 824c1371..f3dafbcb 100644 --- a/examples/console_log/index.js +++ b/examples/console_log/index.js @@ -1,4 +1,4 @@ // For more comments about what's going on here, check out the `hello_world` // example -import('./console_log') +import('./pkg/console_log') .catch(console.error); diff --git a/examples/console_log/package.json b/examples/console_log/package.json index 806119cd..9fafb189 100644 --- a/examples/console_log/package.json +++ b/examples/console_log/package.json @@ -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", diff --git a/examples/console_log/webpack.config.js b/examples/console_log/webpack.config.js index f15dc6b5..a6f6e1e9 100644 --- a/examples/console_log/webpack.config.js +++ b/examples/console_log/webpack.config.js @@ -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,8 +10,9 @@ module.exports = { filename: 'index.js', }, plugins: [ - new HtmlWebpackPlugin({ - template: "index.html" + new HtmlWebpackPlugin(), + new WasmPackPlugin({ + crateDirectory: path.resolve(__dirname, ".") }), // Have this example work in Edge which doesn't ship `TextEncoder` or // `TextDecoder` at this time. diff --git a/examples/dom/.gitignore b/examples/dom/.gitignore deleted file mode 100644 index 1fbaedd8..00000000 --- a/examples/dom/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -package-lock.json -dom.js -dom_bg.js -dom_bg.wasm diff --git a/examples/dom/README.md b/examples/dom/README.md index 6fd6c372..2a7f6789 100644 --- a/examples/dom/README.md +++ b/examples/dom/README.md @@ -9,9 +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! diff --git a/examples/dom/build.sh b/examples/dom/build.sh deleted file mode 100755 index 0b5e4b65..00000000 --- a/examples/dom/build.sh +++ /dev/null @@ -1,12 +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/dom.wasm --out-dir . -npm install -npm run serve diff --git a/examples/dom/index.js b/examples/dom/index.js index 0d74f2fa..7defc51d 100644 --- a/examples/dom/index.js +++ b/examples/dom/index.js @@ -1,4 +1,4 @@ // For more comments about what's going on here, check out the `hello_world` // example -import('./dom') +import('./pkg/dom') .catch(console.error); diff --git a/examples/dom/package.json b/examples/dom/package.json index 806119cd..9fafb189 100644 --- a/examples/dom/package.json +++ b/examples/dom/package.json @@ -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", diff --git a/examples/dom/webpack.config.js b/examples/dom/webpack.config.js index f15dc6b5..25afd180 100644 --- a/examples/dom/webpack.config.js +++ b/examples/dom/webpack.config.js @@ -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,7 +11,10 @@ module.exports = { }, plugins: [ new HtmlWebpackPlugin({ - template: "index.html" + 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. diff --git a/examples/duck-typed-interfaces/.gitignore b/examples/duck-typed-interfaces/.gitignore deleted file mode 100644 index 2a3ddc15..00000000 --- a/examples/duck-typed-interfaces/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -package-lock.json -rust_duck_typed_interfaces.js -rust_duck_typed_interfaces_bg.js -rust_duck_typed_interfaces_bg.wasm diff --git a/examples/duck-typed-interfaces/README.md b/examples/duck-typed-interfaces/README.md index 5cd195e5..f237bdbc 100644 --- a/examples/duck-typed-interfaces/README.md +++ b/examples/duck-typed-interfaces/README.md @@ -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. diff --git a/examples/duck-typed-interfaces/build.sh b/examples/duck-typed-interfaces/build.sh deleted file mode 100755 index c0ffd7cf..00000000 --- a/examples/duck-typed-interfaces/build.sh +++ /dev/null @@ -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 diff --git a/examples/duck-typed-interfaces/index.js b/examples/duck-typed-interfaces/index.js index fe8a21ef..beb99169 100644 --- a/examples/duck-typed-interfaces/index.js +++ b/examples/duck-typed-interfaces/index.js @@ -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'); diff --git a/examples/duck-typed-interfaces/package.json b/examples/duck-typed-interfaces/package.json index 806119cd..9fafb189 100644 --- a/examples/duck-typed-interfaces/package.json +++ b/examples/duck-typed-interfaces/package.json @@ -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", diff --git a/examples/duck-typed-interfaces/webpack.config.js b/examples/duck-typed-interfaces/webpack.config.js index 53396f30..25afd180 100644 --- a/examples/duck-typed-interfaces/webpack.config.js +++ b/examples/duck-typed-interfaces/webpack.config.js @@ -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({ diff --git a/examples/fetch/.gitignore b/examples/fetch/.gitignore deleted file mode 100644 index cf66a572..00000000 --- a/examples/fetch/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -fetch.d.ts -fetch.js -fetch_bg.wasm -package-lock.json diff --git a/examples/fetch/README.md b/examples/fetch/README.md index c3392896..a3563373 100644 --- a/examples/fetch/README.md +++ b/examples/fetch/README.md @@ -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! - diff --git a/examples/fetch/build.sh b/examples/fetch/build.sh deleted file mode 100755 index ffaaf4f9..00000000 --- a/examples/fetch/build.sh +++ /dev/null @@ -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 diff --git a/examples/fetch/index.js b/examples/fetch/index.js index 7a525f1c..16c31681 100644 --- a/examples/fetch/index.js +++ b/examples/fetch/index.js @@ -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); diff --git a/examples/fetch/package.json b/examples/fetch/package.json index 806119cd..9fafb189 100644 --- a/examples/fetch/package.json +++ b/examples/fetch/package.json @@ -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", diff --git a/examples/fetch/webpack.config.js b/examples/fetch/webpack.config.js index 53396f30..a6f6e1e9 100644 --- a/examples/fetch/webpack.config.js +++ b/examples/fetch/webpack.config.js @@ -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({ diff --git a/examples/guide-supported-types-examples/.gitignore b/examples/guide-supported-types-examples/.gitignore deleted file mode 100644 index d0b14fad..00000000 --- a/examples/guide-supported-types-examples/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -package-lock.json -guide_supported_types_examples.js -guide_supported_types_examples_bg.wasm diff --git a/examples/guide-supported-types-examples/build.sh b/examples/guide-supported-types-examples/build.sh deleted file mode 100755 index 0ee158b8..00000000 --- a/examples/guide-supported-types-examples/build.sh +++ /dev/null @@ -1,12 +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 --release -cargo run --manifest-path ../../crates/cli/Cargo.toml \ - --bin wasm-bindgen -- \ - ../../target/wasm32-unknown-unknown/release/guide_supported_types_examples.wasm --out-dir . -npm install -npm run serve diff --git a/examples/guide-supported-types-examples/index.js b/examples/guide-supported-types-examples/index.js index a1819bb5..c5969879 100644 --- a/examples/guide-supported-types-examples/index.js +++ b/examples/guide-supported-types-examples/index.js @@ -1,5 +1,5 @@ // For more comments about what's going on here, check out the `hello_world` // example -import('./bootstrap').then(() => { - console.log("done"); -}); +// import('./pkg/bootstrap').then(() => { +// console.log("done"); +// }); diff --git a/examples/guide-supported-types-examples/package.json b/examples/guide-supported-types-examples/package.json index 806119cd..9fafb189 100644 --- a/examples/guide-supported-types-examples/package.json +++ b/examples/guide-supported-types-examples/package.json @@ -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", diff --git a/examples/guide-supported-types-examples/webpack.config.js b/examples/guide-supported-types-examples/webpack.config.js index 53396f30..a6f6e1e9 100644 --- a/examples/guide-supported-types-examples/webpack.config.js +++ b/examples/guide-supported-types-examples/webpack.config.js @@ -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({ diff --git a/examples/hello_world/.gitignore b/examples/hello_world/.gitignore deleted file mode 100644 index f5974ab0..00000000 --- a/examples/hello_world/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -package-lock.json -hello_world.js -hello_world_bg.js -hello_world_bg.wasm diff --git a/examples/hello_world/README.md b/examples/hello_world/README.md index 74eda63c..efaca0de 100644 --- a/examples/hello_world/README.md +++ b/examples/hello_world/README.md @@ -9,9 +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 show a dialog! +and then visiting http://localhost:8080 in a browser should run the example! diff --git a/examples/hello_world/build.sh b/examples/hello_world/build.sh deleted file mode 100755 index 38691904..00000000 --- a/examples/hello_world/build.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -set -ex - -# Build the `hello_world.wasm` file using Cargo/rustc -cargo build --target wasm32-unknown-unknown - -# Run the `wasm-bindgen` CLI tool to postprocess the wasm file emitted by the -# Rust compiler to emit the JS support glue that's necessary -# -# Here we're using the version of the CLI in this repository, but for external -# usage you'd use the commented out version below -cargo run --manifest-path ../../crates/cli/Cargo.toml \ - --bin wasm-bindgen -- \ - ../../target/wasm32-unknown-unknown/debug/hello_world.wasm --out-dir . -# wasm-bindgen ../../target/wasm32-unknown-unknown/hello_world.wasm --out-dir . - -# Finally, package everything up using Webpack and start a server so we can -# browse the result -npm install -npm run serve diff --git a/examples/hello_world/index.js b/examples/hello_world/index.js index 99946b15..d7d7a65a 100644 --- a/examples/hello_world/index.js +++ b/examples/hello_world/index.js @@ -1,7 +1,7 @@ // Note that a dynamic `import` statement here is required due to -// webpack/webpack#6615, but in theory `import { greet } from './hello_world';` +// webpack/webpack#6615, but in theory `import { greet } from './pkg/hello_world';` // will work here one day as well! -const rust = import('./hello_world'); +const rust = import('./pkg/hello_world'); rust .then(m => m.greet('World!')) diff --git a/examples/hello_world/package.json b/examples/hello_world/package.json index 806119cd..9fafb189 100644 --- a/examples/hello_world/package.json +++ b/examples/hello_world/package.json @@ -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", diff --git a/examples/hello_world/webpack.config.js b/examples/hello_world/webpack.config.js index 53396f30..a6f6e1e9 100644 --- a/examples/hello_world/webpack.config.js +++ b/examples/hello_world/webpack.config.js @@ -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({ diff --git a/examples/import_js/.gitignore b/examples/import_js/.gitignore deleted file mode 100644 index bd9c9eb3..00000000 --- a/examples/import_js/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -package-lock.json -import_js.js -import_js_bg.js -import_js_bg.wasm diff --git a/examples/import_js/README.md b/examples/import_js/README.md index a8badf7a..7a4249ed 100644 --- a/examples/import_js/README.md +++ b/examples/import_js/README.md @@ -9,9 +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! diff --git a/examples/import_js/build.sh b/examples/import_js/build.sh deleted file mode 100755 index 754509cb..00000000 --- a/examples/import_js/build.sh +++ /dev/null @@ -1,12 +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/import_js.wasm --out-dir . -npm install -npm run serve diff --git a/examples/import_js/index.js b/examples/import_js/index.js index 9d7e3b1a..0c41f50d 100644 --- a/examples/import_js/index.js +++ b/examples/import_js/index.js @@ -1,4 +1,4 @@ // For more comments about what's going on here, check out the `hello_world` // example -import('./import_js') +import('./pkg/import_js') .catch(console.error); diff --git a/examples/import_js/package.json b/examples/import_js/package.json index 806119cd..9fafb189 100644 --- a/examples/import_js/package.json +++ b/examples/import_js/package.json @@ -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", diff --git a/examples/import_js/src/lib.rs b/examples/import_js/src/lib.rs index a010ca93..365eddce 100644 --- a/examples/import_js/src/lib.rs +++ b/examples/import_js/src/lib.rs @@ -1,6 +1,6 @@ use wasm_bindgen::prelude::*; -#[wasm_bindgen(module = "./defined-in-js")] +#[wasm_bindgen(module = "../defined-in-js")] extern "C" { fn name() -> String; diff --git a/examples/import_js/webpack.config.js b/examples/import_js/webpack.config.js index f15dc6b5..25afd180 100644 --- a/examples/import_js/webpack.config.js +++ b/examples/import_js/webpack.config.js @@ -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,7 +11,10 @@ module.exports = { }, plugins: [ new HtmlWebpackPlugin({ - template: "index.html" + 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. diff --git a/examples/julia_set/.gitignore b/examples/julia_set/.gitignore deleted file mode 100644 index b76bec79..00000000 --- a/examples/julia_set/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -julia_set.js -julia_set_bg.wasm \ No newline at end of file diff --git a/examples/julia_set/README.md b/examples/julia_set/README.md index 64d37e23..913ad8c8 100644 --- a/examples/julia_set/README.md +++ b/examples/julia_set/README.md @@ -9,9 +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! diff --git a/examples/julia_set/build.sh b/examples/julia_set/build.sh deleted file mode 100755 index 8c887ffb..00000000 --- a/examples/julia_set/build.sh +++ /dev/null @@ -1,12 +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 --release -cargo run --manifest-path ../../crates/cli/Cargo.toml \ - --bin wasm-bindgen -- \ - ../../target/wasm32-unknown-unknown/release/julia_set.wasm --out-dir . -npm install -npm run serve diff --git a/examples/julia_set/index.js b/examples/julia_set/index.js index 88104731..4e721fe7 100644 --- a/examples/julia_set/index.js +++ b/examples/julia_set/index.js @@ -1,4 +1,4 @@ -import('./julia_set') +import('./pkg/julia_set') .then(wasm => { const canvas = document.getElementById('drawing'); const ctx = canvas.getContext('2d'); diff --git a/examples/julia_set/package.json b/examples/julia_set/package.json index 806119cd..9fafb189 100644 --- a/examples/julia_set/package.json +++ b/examples/julia_set/package.json @@ -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", diff --git a/examples/julia_set/webpack.config.js b/examples/julia_set/webpack.config.js index f15dc6b5..25afd180 100644 --- a/examples/julia_set/webpack.config.js +++ b/examples/julia_set/webpack.config.js @@ -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,7 +11,10 @@ module.exports = { }, plugins: [ new HtmlWebpackPlugin({ - template: "index.html" + 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. diff --git a/examples/no_modules/.gitignore b/examples/no_modules/.gitignore deleted file mode 100644 index fe50a548..00000000 --- a/examples/no_modules/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -no_modules.js -no_modules_bg.wasm diff --git a/examples/no_modules/README.md b/examples/no_modules/README.md index c6eb4883..54f66e9c 100644 --- a/examples/no_modules/README.md +++ b/examples/no_modules/README.md @@ -7,9 +7,7 @@ You can build the example locally with: ``` -$ ./build.sh +$ wasm-pack build --target no-modules ``` -(or running the commands on Windows manually) - and then opening `index.html` in a browser should run the example! diff --git a/examples/no_modules/build.sh b/examples/no_modules/build.sh deleted file mode 100755 index 987e01e1..00000000 --- a/examples/no_modules/build.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -set -ex - -cargo build --target wasm32-unknown-unknown - -cargo run --manifest-path ../../crates/cli/Cargo.toml \ - --bin wasm-bindgen -- \ - --no-modules \ - ../../target/wasm32-unknown-unknown/debug/no_modules.wasm --out-dir . - -python -m SimpleHTTPServer diff --git a/examples/no_modules/index.html b/examples/no_modules/index.html index 50193bc3..979a8621 100644 --- a/examples/no_modules/index.html +++ b/examples/no_modules/index.html @@ -17,7 +17,7 @@ - + diff --git a/examples/paint/.gitignore b/examples/paint/.gitignore deleted file mode 100644 index 4f5a7e18..00000000 --- a/examples/paint/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -package-lock.json -wasm_bindgen_paint.js -wasm_bindgen_paint_bg.js -wasm_bindgen_paint_bg.wasm diff --git a/examples/paint/README.md b/examples/paint/README.md index c1909b2e..d0bfc1b7 100644 --- a/examples/paint/README.md +++ b/examples/paint/README.md @@ -9,9 +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! diff --git a/examples/paint/build.sh b/examples/paint/build.sh deleted file mode 100755 index 2b372d5a..00000000 --- a/examples/paint/build.sh +++ /dev/null @@ -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/wasm_bindgen_paint.wasm --out-dir . - -npm install -npm run serve diff --git a/examples/paint/index.js b/examples/paint/index.js index 6775ddb4..a674d057 100644 --- a/examples/paint/index.js +++ b/examples/paint/index.js @@ -1,4 +1,4 @@ // For more comments about what's going on here, check out the `hello_world` // example. -import('./wasm_bindgen_paint') +import('./pkg/wasm_bindgen_paint') .catch(console.error); diff --git a/examples/paint/package.json b/examples/paint/package.json index 806119cd..9fafb189 100644 --- a/examples/paint/package.json +++ b/examples/paint/package.json @@ -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", diff --git a/examples/paint/webpack.config.js b/examples/paint/webpack.config.js index f15dc6b5..25afd180 100644 --- a/examples/paint/webpack.config.js +++ b/examples/paint/webpack.config.js @@ -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,7 +11,10 @@ module.exports = { }, plugins: [ new HtmlWebpackPlugin({ - template: "index.html" + 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. diff --git a/examples/performance/.gitignore b/examples/performance/.gitignore deleted file mode 100644 index 72304881..00000000 --- a/examples/performance/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -package-lock.json -performance.js -performance_bg.js -performance_bg.wasm diff --git a/examples/performance/README.md b/examples/performance/README.md index f328264d..8f414e06 100644 --- a/examples/performance/README.md +++ b/examples/performance/README.md @@ -9,9 +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! diff --git a/examples/performance/build.sh b/examples/performance/build.sh deleted file mode 100755 index f50e8205..00000000 --- a/examples/performance/build.sh +++ /dev/null @@ -1,12 +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/performance.wasm --out-dir . -npm install -npm run serve diff --git a/examples/performance/index.js b/examples/performance/index.js index 0c7c097c..e653d69e 100644 --- a/examples/performance/index.js +++ b/examples/performance/index.js @@ -1,4 +1,4 @@ // For more comments about what's going on here, check out the `hello_world` // example -import('./performance') +import('./pkg/performance') .catch(console.error); diff --git a/examples/performance/package.json b/examples/performance/package.json index 806119cd..9fafb189 100644 --- a/examples/performance/package.json +++ b/examples/performance/package.json @@ -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", diff --git a/examples/performance/webpack.config.js b/examples/performance/webpack.config.js index f15dc6b5..25afd180 100644 --- a/examples/performance/webpack.config.js +++ b/examples/performance/webpack.config.js @@ -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,7 +11,10 @@ module.exports = { }, plugins: [ new HtmlWebpackPlugin({ - template: "index.html" + 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. diff --git a/examples/raytrace-parallel/.gitignore b/examples/raytrace-parallel/.gitignore deleted file mode 100644 index 6ea62659..00000000 --- a/examples/raytrace-parallel/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -package-lock.json -raytrace_parallel.js -raytrace_parallel_bg.wasm diff --git a/examples/request-animation-frame/.gitignore b/examples/request-animation-frame/.gitignore deleted file mode 100644 index f4336279..00000000 --- a/examples/request-animation-frame/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -package-lock.json -request_animation_frame.js -request_animation_frame_bg.js -request_animation_frame_bg.wasm diff --git a/examples/request-animation-frame/README.md b/examples/request-animation-frame/README.md index 48974541..1144eac4 100644 --- a/examples/request-animation-frame/README.md +++ b/examples/request-animation-frame/README.md @@ -9,9 +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! diff --git a/examples/request-animation-frame/build.sh b/examples/request-animation-frame/build.sh deleted file mode 100755 index 12609c36..00000000 --- a/examples/request-animation-frame/build.sh +++ /dev/null @@ -1,12 +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/request_animation_frame.wasm --out-dir . -npm install -npm run serve diff --git a/examples/request-animation-frame/index.js b/examples/request-animation-frame/index.js index ea5b0668..de9aa204 100644 --- a/examples/request-animation-frame/index.js +++ b/examples/request-animation-frame/index.js @@ -1,4 +1,4 @@ // For more comments about what's going on here, check out the `hello_world` // example -import('./request_animation_frame') +import('./pkg/request_animation_frame') .catch(console.error); diff --git a/examples/request-animation-frame/package.json b/examples/request-animation-frame/package.json index 806119cd..9fafb189 100644 --- a/examples/request-animation-frame/package.json +++ b/examples/request-animation-frame/package.json @@ -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", diff --git a/examples/request-animation-frame/webpack.config.js b/examples/request-animation-frame/webpack.config.js index f15dc6b5..25afd180 100644 --- a/examples/request-animation-frame/webpack.config.js +++ b/examples/request-animation-frame/webpack.config.js @@ -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,7 +11,10 @@ module.exports = { }, plugins: [ new HtmlWebpackPlugin({ - template: "index.html" + 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. diff --git a/examples/todomvc/.gitignore b/examples/todomvc/.gitignore deleted file mode 100644 index caf09561..00000000 --- a/examples/todomvc/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -target/ -dist/ -_site/ - -todomvc* -*.swp diff --git a/examples/todomvc/README.md b/examples/todomvc/README.md index 1f201507..2a6a2577 100644 --- a/examples/todomvc/README.md +++ b/examples/todomvc/README.md @@ -9,9 +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! diff --git a/examples/todomvc/build.sh b/examples/todomvc/build.sh deleted file mode 100755 index 055784b2..00000000 --- a/examples/todomvc/build.sh +++ /dev/null @@ -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/todomvc.wasm --out-dir . - -npm install -npm run serve diff --git a/examples/todomvc/index.js b/examples/todomvc/index.js index 7190d16b..29a450d1 100644 --- a/examples/todomvc/index.js +++ b/examples/todomvc/index.js @@ -1,4 +1,4 @@ // For more comments about what's going on here, check out the `hello_world` // example -import('./todomvc') +import('./pkg/todomvc') .catch(console.error); diff --git a/examples/todomvc/package.json b/examples/todomvc/package.json index 31461e15..9fafb189 100644 --- a/examples/todomvc/package.json +++ b/examples/todomvc/package.json @@ -4,9 +4,9 @@ "serve": "webpack-dev-server" }, "devDependencies": { - "copy-webpack-plugin": "^4.6.0", - "html-webpack-plugin": "^3.2.0", + "@wasm-tool/wasm-pack-plugin": "0.2.1", "text-encoding": "^0.7.0", + "html-webpack-plugin": "^3.2.0", "webpack": "^4.11.1", "webpack-cli": "^3.1.1", "webpack-dev-server": "^3.1.0" diff --git a/examples/todomvc/webpack.config.js b/examples/todomvc/webpack.config.js index bfd5d8a5..25afd180 100644 --- a/examples/todomvc/webpack.config.js +++ b/examples/todomvc/webpack.config.js @@ -1,7 +1,7 @@ const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); const webpack = require('webpack'); +const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin"); module.exports = { entry: './index.js', @@ -11,12 +11,11 @@ module.exports = { }, plugins: [ new HtmlWebpackPlugin({ - template: "index.html" + template: 'index.html' + }), + new WasmPackPlugin({ + crateDirectory: path.resolve(__dirname, ".") }), - new CopyWebpackPlugin([ - { from: 'index.css', to: 'index.css' }, - ]), - // Have this example work in Edge which doesn't ship `TextEncoder` or // `TextDecoder` at this time. new webpack.ProvidePlugin({ diff --git a/examples/wasm-in-wasm/.gitignore b/examples/wasm-in-wasm/.gitignore deleted file mode 100644 index e2ac0884..00000000 --- a/examples/wasm-in-wasm/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -package-lock.json -wasm_in_wasm.js -wasm_in_wasm_bg.js -wasm_in_wasm_bg.wasm diff --git a/examples/wasm-in-wasm/README.md b/examples/wasm-in-wasm/README.md index ab17ae81..e618e4a1 100644 --- a/examples/wasm-in-wasm/README.md +++ b/examples/wasm-in-wasm/README.md @@ -9,9 +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! diff --git a/examples/wasm-in-wasm/build.sh b/examples/wasm-in-wasm/build.sh deleted file mode 100755 index 0b85c435..00000000 --- a/examples/wasm-in-wasm/build.sh +++ /dev/null @@ -1,12 +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/wasm_in_wasm.wasm --out-dir . -npm install -npm run serve diff --git a/examples/wasm-in-wasm/index.js b/examples/wasm-in-wasm/index.js index a8df06e5..d0791298 100644 --- a/examples/wasm-in-wasm/index.js +++ b/examples/wasm-in-wasm/index.js @@ -1,4 +1,4 @@ // For more comments about what's going on here, check out the `hello_world` // example -import('./wasm_in_wasm') +import('./pkg/wasm_in_wasm') .catch(console.error); diff --git a/examples/wasm-in-wasm/package.json b/examples/wasm-in-wasm/package.json index 806119cd..9fafb189 100644 --- a/examples/wasm-in-wasm/package.json +++ b/examples/wasm-in-wasm/package.json @@ -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", diff --git a/examples/wasm-in-wasm/webpack.config.js b/examples/wasm-in-wasm/webpack.config.js index f15dc6b5..25afd180 100644 --- a/examples/wasm-in-wasm/webpack.config.js +++ b/examples/wasm-in-wasm/webpack.config.js @@ -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,7 +11,10 @@ module.exports = { }, plugins: [ new HtmlWebpackPlugin({ - template: "index.html" + 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. diff --git a/examples/wasm2js/.gitignore b/examples/wasm2js/.gitignore deleted file mode 100644 index 16611626..00000000 --- a/examples/wasm2js/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -package-lock.json -wasm2js* diff --git a/examples/wasm2js/build.sh b/examples/wasm2js/build.sh index 62724273..9100b26c 100755 --- a/examples/wasm2js/build.sh +++ b/examples/wasm2js/build.sh @@ -3,16 +3,13 @@ set -ex # Compile our wasm module and run `wasm-bindgen` -cargo build --target wasm32-unknown-unknown --release -cargo run --manifest-path ../../crates/cli/Cargo.toml \ - --bin wasm-bindgen -- \ - ../../target/wasm32-unknown-unknown/release/wasm2js.wasm --out-dir . +wasm-pack build # Run the `wasm2js` tool from `binaryen` -wasm2js wasm2js_bg.wasm -o wasm2js_bg.js +wasm2js pkg/wasm2js_bg.wasm -o pkg/wasm2js_bg.js # Move our original wasm out of the way to avoid cofusing Webpack. -mv wasm2js_bg.wasm wasm2js_bg.bak.wasm +mv pkg/wasm2js_bg.wasm pkg/wasm2js_bg.bak.wasm npm install npm run serve diff --git a/examples/wasm2js/index.js b/examples/wasm2js/index.js index 63ed378e..27ed1ebe 100644 --- a/examples/wasm2js/index.js +++ b/examples/wasm2js/index.js @@ -1,4 +1,4 @@ // Note that since we're not using `WebAssembly` we can do a synchronous import // here! -import { run } from './wasm2js'; +import { run } from './pkg/wasm2js'; run(); diff --git a/examples/webaudio/.gitignore b/examples/webaudio/.gitignore deleted file mode 100644 index 89f520ca..00000000 --- a/examples/webaudio/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -package-lock.json -node_modules/ -webaudio.js -webaudio_bg.wasm diff --git a/examples/webaudio/README.md b/examples/webaudio/README.md index 14d4b50f..7443df73 100644 --- a/examples/webaudio/README.md +++ b/examples/webaudio/README.md @@ -9,9 +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! diff --git a/examples/webaudio/build.sh b/examples/webaudio/build.sh deleted file mode 100755 index 61134fff..00000000 --- a/examples/webaudio/build.sh +++ /dev/null @@ -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/webaudio.wasm --out-dir . - -npm install -npm run serve diff --git a/examples/webaudio/index.js b/examples/webaudio/index.js index db9c821e..6ff2e02f 100644 --- a/examples/webaudio/index.js +++ b/examples/webaudio/index.js @@ -1,4 +1,4 @@ -import('./webaudio') +import('./pkg/webaudio') .then(rust_module => { let fm = null; diff --git a/examples/webaudio/package.json b/examples/webaudio/package.json index 806119cd..9fafb189 100644 --- a/examples/webaudio/package.json +++ b/examples/webaudio/package.json @@ -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", diff --git a/examples/webaudio/webpack.config.js b/examples/webaudio/webpack.config.js index f15dc6b5..25afd180 100644 --- a/examples/webaudio/webpack.config.js +++ b/examples/webaudio/webpack.config.js @@ -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,7 +11,10 @@ module.exports = { }, plugins: [ new HtmlWebpackPlugin({ - template: "index.html" + 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. diff --git a/examples/webgl/.gitignore b/examples/webgl/.gitignore deleted file mode 100644 index 3955bd3c..00000000 --- a/examples/webgl/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -package-lock.json -webgl.js -webgl_bg.js -webgl_bg.wasm diff --git a/examples/webgl/README.md b/examples/webgl/README.md index e6de7fb3..74871f6a 100644 --- a/examples/webgl/README.md +++ b/examples/webgl/README.md @@ -9,9 +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! diff --git a/examples/webgl/build.sh b/examples/webgl/build.sh deleted file mode 100755 index e2720380..00000000 --- a/examples/webgl/build.sh +++ /dev/null @@ -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/webgl.wasm --out-dir . - -npm install -npm run serve diff --git a/examples/webgl/index.js b/examples/webgl/index.js index dc67e610..6cc5f9c8 100644 --- a/examples/webgl/index.js +++ b/examples/webgl/index.js @@ -1,4 +1,4 @@ // For more comments about what's going on here, check out the `hello_world` // example. -import('./webgl') +import('./pkg/webgl') .catch(console.error); diff --git a/examples/webgl/package.json b/examples/webgl/package.json index 806119cd..9fafb189 100644 --- a/examples/webgl/package.json +++ b/examples/webgl/package.json @@ -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", diff --git a/examples/webgl/webpack.config.js b/examples/webgl/webpack.config.js index f15dc6b5..797f429f 100644 --- a/examples/webgl/webpack.config.js +++ b/examples/webgl/webpack.config.js @@ -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,8 +11,11 @@ module.exports = { }, plugins: [ new HtmlWebpackPlugin({ - template: "index.html" + 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({ diff --git a/guide/src/examples/index.md b/guide/src/examples/index.md index 4ca1307a..2136e8da 100644 --- a/guide/src/examples/index.md +++ b/guide/src/examples/index.md @@ -5,8 +5,9 @@ This subsection contains examples of using the `wasm-bindgen`, `js-sys`, and doing. The source code for all examples can also be [found online][code] to download an -run locally. Each example is accompanied with a `build.sh` script to outline the -steps necessary to build and run it as well. +run locally. Most examples are configured with Webpack/`wasm-pack` and can +be built with `npm run serve`. Other examples which don't use Webpack are +accompanied with a `build.sh` showing how to build it. Note that most examples currently use Webpack to assemble the final output artifact, but this is not required! You can use the bundler of choice, diff --git a/package.json b/package.json index a1df7392..b43d0154 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,14 @@ { - "license": "MIT", + "scripts": { + "build": "webpack -p", + "serve": "webpack-dev-server -p" + }, "devDependencies": { + "@wasm-tool/wasm-pack-plugin": "0.2.0", "text-encoding": "^0.7.0", "html-webpack-plugin": "^3.2.0", - "webpack": "^4.17.1", + "webpack": "^4.11.1", "webpack-cli": "^3.1.1", - "webpack-dev-server": "^3.1.6", - "copy-webpack-plugin": "^4.6.0" + "webpack-dev-server": "^3.1.0" } }