diff --git a/.travis.yml b/.travis.yml index 92c3bf9868d..8ef712e68da 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 00000000000..20fec396ebc --- /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 bdaab9c5794..00000000000 --- 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 57c508e85e9..a72caf3c703 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 8d2dd6e8b89..00000000000 --- 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 bef9fbcc661..e8f5245025d 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 806119cdb5b..49198ff2cd0 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 53396f30f8a..a6f6e1e930d 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 a5e6169e744..00000000000 --- 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 2ab89e80121..bbd03128895 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 0198ef80a47..00000000000 --- 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 4b586d9a0f6..a649b473e1e 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 806119cdb5b..9fafb189ee8 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 f15dc6b56d9..25afd18002a 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 937451e4320..00000000000 --- 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 884d9a621db..4f0ec173629 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 7e4aa2f14e6..00000000000 --- 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 c1d0f4f59c5..caa92b42428 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 806119cdb5b..9fafb189ee8 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 f15dc6b56d9..353fbcafdc9 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 3e0dcd94898..00000000000 --- 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 5782c28aad6..ddf701710bf 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 9ed029a9440..00000000000 --- 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 cc27e0576d7..5fb5aa35598 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 806119cdb5b..9fafb189ee8 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 f15dc6b56d9..a6f6e1e930d 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 4fd1390e0ab..00000000000 --- 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 c72b418cded..32fa8d49b96 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 f2594d41ca3..00000000000 --- 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 824c1371baa..f3dafbcba0b 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 806119cdb5b..9fafb189ee8 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 f15dc6b56d9..a6f6e1e930d 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 1fbaedd8631..00000000000 --- 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 6fd6c3727b1..2a7f678914a 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 0b5e4b65a1a..00000000000 --- 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 0d74f2fa82f..7defc51d681 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 806119cdb5b..9fafb189ee8 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 f15dc6b56d9..25afd18002a 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 2a3ddc1528a..00000000000 --- 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 5cd195e5111..f237bdbcf25 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 c0ffd7cf11f..00000000000 --- 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 fe8a21ef45c..beb99169cd2 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 806119cdb5b..9fafb189ee8 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 53396f30f8a..25afd18002a 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 cf66a5724f3..00000000000 --- 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 c339289623d..a3563373752 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 ffaaf4f98b3..00000000000 --- 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 7a525f1c39c..16c31681da3 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 806119cdb5b..9fafb189ee8 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 53396f30f8a..a6f6e1e930d 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 d0b14fad7d9..00000000000 --- 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 0ee158b88c8..00000000000 --- 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 a1819bb5f83..c5969879e2e 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 806119cdb5b..9fafb189ee8 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 53396f30f8a..a6f6e1e930d 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 f5974ab0b6b..00000000000 --- 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 74eda63cc2a..efaca0de014 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 38691904169..00000000000 --- 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 99946b153a4..d7d7a65a27d 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 806119cdb5b..9fafb189ee8 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 53396f30f8a..a6f6e1e930d 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 bd9c9eb38cf..00000000000 --- 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 a8badf7ab05..7a4249eda9a 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 754509cbb95..00000000000 --- 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 9d7e3b1a1ca..0c41f50d3d6 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 806119cdb5b..9fafb189ee8 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 a010ca93ce1..365eddcef44 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 f15dc6b56d9..25afd18002a 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 b76bec79eb0..00000000000 --- 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 64d37e237a1..913ad8c8d17 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 8c887ffb300..00000000000 --- 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 881047310d9..4e721fe7a7e 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 806119cdb5b..9fafb189ee8 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 f15dc6b56d9..25afd18002a 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 fe50a54856c..00000000000 --- 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 c6eb48838b1..54f66e9c2e6 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 987e01e1e80..00000000000 --- 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 50193bc3629..979a8621242 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 4f5a7e18538..00000000000 --- 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 c1909b2e4d5..d0bfc1b734a 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 2b372d5a1bf..00000000000 --- 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 6775ddb4cb4..a674d057295 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 806119cdb5b..9fafb189ee8 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 f15dc6b56d9..25afd18002a 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 72304881dce..00000000000 --- 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 f328264d950..8f414e062ab 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 f50e8205ecc..00000000000 --- 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 0c7c097cab5..e653d69e4e4 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 806119cdb5b..9fafb189ee8 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 f15dc6b56d9..25afd18002a 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 6ea6265970f..00000000000 --- 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 f4336279eeb..00000000000 --- 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 48974541255..1144eac41de 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 12609c36937..00000000000 --- 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 ea5b0668122..de9aa20415e 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 806119cdb5b..9fafb189ee8 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 f15dc6b56d9..25afd18002a 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 caf09561af9..00000000000 --- 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 1f201507629..2a6a25771c4 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 055784b2ce8..00000000000 --- 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 7190d16b173..29a450d1ae4 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 31461e15e66..9fafb189ee8 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 bfd5d8a5a6e..25afd18002a 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 e2ac0884184..00000000000 --- 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 ab17ae81137..e618e4a1a4f 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 0b85c435837..00000000000 --- 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 a8df06e590e..d079129814e 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 806119cdb5b..9fafb189ee8 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 f15dc6b56d9..25afd18002a 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 16611626c2c..00000000000 --- 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 6272427383a..9100b26cd34 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 63ed378ebb3..27ed1ebeaf5 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 89f520ca351..00000000000 --- 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 14d4b50f20d..7443df73264 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 61134fffabb..00000000000 --- 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 db9c821e983..6ff2e02f9fe 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 806119cdb5b..9fafb189ee8 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 f15dc6b56d9..25afd18002a 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 3955bd3cf61..00000000000 --- 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 e6de7fb386a..74871f6a090 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 e2720380769..00000000000 --- 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 dc67e61039a..6cc5f9c8b68 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 806119cdb5b..9fafb189ee8 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 f15dc6b56d9..797f429f0f7 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 4ca1307a806..2136e8da532 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 a1df7392b0b..b43d01545ce 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" } }