Skip to content

Commit

Permalink
Merge pull request rustwasm#1159 from alexcrichton/webpack
Browse files Browse the repository at this point in the history
Convert all examples to using wasm-pack
  • Loading branch information
alexcrichton authored Jan 18, 2019
2 parents ba732a8 + 32c611d commit 71ed305
Show file tree
Hide file tree
Showing 126 changed files with 180 additions and 481 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package-lock.json
pkg
dist
wasm-pack.log
3 changes: 0 additions & 3 deletions examples/add/.gitignore

This file was deleted.

4 changes: 1 addition & 3 deletions examples/add/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
12 changes: 0 additions & 12 deletions examples/add/build.sh

This file was deleted.

2 changes: 1 addition & 1 deletion examples/add/index.js
Original file line number Diff line number Diff line change
@@ -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);
5 changes: 3 additions & 2 deletions examples/add/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 4 additions & 0 deletions examples/add/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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({
Expand Down
4 changes: 0 additions & 4 deletions examples/canvas/.gitignore

This file was deleted.

4 changes: 1 addition & 3 deletions examples/canvas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
15 changes: 0 additions & 15 deletions examples/canvas/build.sh

This file was deleted.

2 changes: 1 addition & 1 deletion examples/canvas/index.js
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions examples/canvas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion examples/canvas/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions examples/char/.gitignore

This file was deleted.

4 changes: 1 addition & 3 deletions examples/char/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
22 changes: 0 additions & 22 deletions examples/char/build.sh

This file was deleted.

2 changes: 1 addition & 1 deletion examples/char/index.js
Original file line number Diff line number Diff line change
@@ -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 = [];
Expand Down
1 change: 1 addition & 0 deletions examples/char/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions examples/char/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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({
Expand Down
4 changes: 0 additions & 4 deletions examples/closures/.gitignore

This file was deleted.

4 changes: 1 addition & 3 deletions examples/closures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
12 changes: 0 additions & 12 deletions examples/closures/build.sh

This file was deleted.

2 changes: 1 addition & 1 deletion examples/closures/index.js
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions examples/closures/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions examples/closures/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions examples/console_log/.gitignore

This file was deleted.

4 changes: 1 addition & 3 deletions examples/console_log/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
12 changes: 0 additions & 12 deletions examples/console_log/build.sh

This file was deleted.

2 changes: 1 addition & 1 deletion examples/console_log/index.js
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions examples/console_log/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions examples/console_log/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions examples/dom/.gitignore

This file was deleted.

4 changes: 1 addition & 3 deletions examples/dom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
12 changes: 0 additions & 12 deletions examples/dom/build.sh

This file was deleted.

2 changes: 1 addition & 1 deletion examples/dom/index.js
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions examples/dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 71ed305

Please sign in to comment.