diff --git a/.travis.yml b/.travis.yml index 3f1a7fb2e..039192400 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 000000000..20fec396e --- /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 bdaab9c57..000000000 --- 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 57c508e85..a72caf3c7 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 8d2dd6e8b..000000000 --- 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 bef9fbcc6..e8f524502 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 806119cdb..49198ff2c 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 53396f30f..a6f6e1e93 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 a5e6169e7..000000000 --- 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 2ab89e801..bbd031288 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 0198ef80a..000000000 --- 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 4b586d9a0..a649b473e 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 806119cdb..9fafb189e 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 f15dc6b56..25afd1800 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 937451e43..000000000 --- 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 884d9a621..4f0ec1736 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 7e4aa2f14..000000000 --- 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 c1d0f4f59..caa92b424 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 806119cdb..9fafb189e 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 f15dc6b56..353fbcafd 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 3e0dcd948..000000000 --- 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 5782c28aa..ddf701710 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 9ed029a94..000000000 --- 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 cc27e0576..5fb5aa355 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 806119cdb..9fafb189e 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 f15dc6b56..a6f6e1e93 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 4fd1390e0..000000000 --- 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 c72b418cd..32fa8d49b 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 f2594d41c..000000000 --- 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 824c1371b..f3dafbcba 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 806119cdb..9fafb189e 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 f15dc6b56..a6f6e1e93 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 1fbaedd86..000000000 --- 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 6fd6c3727..2a7f67891 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 0b5e4b65a..000000000 --- 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 0d74f2fa8..7defc51d6 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 806119cdb..9fafb189e 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 f15dc6b56..25afd1800 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 2a3ddc152..000000000 --- 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 5cd195e51..f237bdbcf 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 c0ffd7cf1..000000000 --- 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 fe8a21ef4..beb99169c 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 806119cdb..9fafb189e 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 53396f30f..25afd1800 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 cf66a5724..000000000 --- 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 c33928962..a35633737 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 ffaaf4f98..000000000 --- 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 7a525f1c3..16c31681d 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 806119cdb..9fafb189e 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 53396f30f..a6f6e1e93 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 d0b14fad7..000000000 --- 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 0ee158b88..000000000 --- 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 a1819bb5f..c5969879e 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 806119cdb..9fafb189e 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 53396f30f..a6f6e1e93 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 f5974ab0b..000000000 --- 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 74eda63cc..efaca0de0 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 386919041..000000000 --- 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 99946b153..d7d7a65a2 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 806119cdb..9fafb189e 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 53396f30f..a6f6e1e93 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 bd9c9eb38..000000000 --- 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 a8badf7ab..7a4249eda 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 754509cbb..000000000 --- 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 9d7e3b1a1..0c41f50d3 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 806119cdb..9fafb189e 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 a010ca93c..365eddcef 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 f15dc6b56..25afd1800 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 b76bec79e..000000000 --- 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 64d37e237..913ad8c8d 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 8c887ffb3..000000000 --- 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 881047310..4e721fe7a 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 806119cdb..9fafb189e 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 f15dc6b56..25afd1800 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 fe50a5485..000000000 --- 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 c6eb48838..54f66e9c2 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 987e01e1e..000000000 --- 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 50193bc36..979a86212 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 4f5a7e185..000000000 --- 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 c1909b2e4..d0bfc1b73 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 2b372d5a1..000000000 --- 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 6775ddb4c..a674d0572 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 806119cdb..9fafb189e 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 f15dc6b56..25afd1800 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 72304881d..000000000 --- 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 f328264d9..8f414e062 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 f50e8205e..000000000 --- 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 0c7c097ca..e653d69e4 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 806119cdb..9fafb189e 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 f15dc6b56..25afd1800 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 6ea626597..000000000 --- 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 f4336279e..000000000 --- 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 489745412..1144eac41 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 12609c369..000000000 --- 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 ea5b06681..de9aa2041 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 806119cdb..9fafb189e 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 f15dc6b56..25afd1800 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 caf09561a..000000000 --- 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 1f2015076..2a6a25771 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 055784b2c..000000000 --- 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 7190d16b1..29a450d1a 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 31461e15e..9fafb189e 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 bfd5d8a5a..25afd1800 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 e2ac08841..000000000 --- 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 ab17ae811..e618e4a1a 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 0b85c4358..000000000 --- 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 a8df06e59..d07912981 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 806119cdb..9fafb189e 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 f15dc6b56..25afd1800 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 16611626c..000000000 --- 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 627242738..9100b26cd 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 63ed378eb..27ed1ebea 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 89f520ca3..000000000 --- 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 14d4b50f2..7443df732 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 61134fffa..000000000 --- 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 db9c821e9..6ff2e02f9 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 806119cdb..9fafb189e 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 f15dc6b56..25afd1800 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 3955bd3cf..000000000 --- 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 e6de7fb38..74871f6a0 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 e27203807..000000000 --- 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 dc67e6103..6cc5f9c8b 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 806119cdb..9fafb189e 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 f15dc6b56..797f429f0 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 4ca1307a8..2136e8da5 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 a1df7392b..b43d01545 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" } }