mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-11 11:15:33 +03:00
Fix the wasm2js example (#1750)
This needed and update now that we're explicitly importing `*.wasm` to import `*.js` instead. Additionally this was moved over to the `web` target to avoid needing Webpack Closes #1743
This commit is contained in:
parent
1f39a3045f
commit
4e19ead71b
@ -14,4 +14,4 @@ $ ./build.sh
|
|||||||
|
|
||||||
(or running the commands on Windows manually)
|
(or running the commands on Windows manually)
|
||||||
|
|
||||||
and then visiting http://localhost:8080 in a browser should run the example!
|
and then visiting http://localhost:8000 in a browser should run the example!
|
||||||
|
@ -3,13 +3,12 @@
|
|||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
# Compile our wasm module and run `wasm-bindgen`
|
# Compile our wasm module and run `wasm-bindgen`
|
||||||
wasm-pack build
|
wasm-pack build --target web
|
||||||
|
|
||||||
# Run the `wasm2js` tool from `binaryen`
|
# Run the `wasm2js` tool from `binaryen`
|
||||||
wasm2js pkg/wasm2js_bg.wasm -o pkg/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.
|
# Update our JS shim to require the JS file instead
|
||||||
mv pkg/wasm2js_bg.wasm pkg/wasm2js_bg.bak.wasm
|
sed -i 's/wasm2js_bg.wasm/wasm2js_bg.js/' pkg/wasm2js.js
|
||||||
|
|
||||||
npm install
|
http
|
||||||
npm run serve
|
|
||||||
|
@ -5,4 +5,5 @@
|
|||||||
<body>
|
<body>
|
||||||
<p>Open up the developer console to see "Hello, World!"</p>
|
<p>Open up the developer console to see "Hello, World!"</p>
|
||||||
</body>
|
</body>
|
||||||
|
<script src=index.js type=module></script>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Note that since we're not using `WebAssembly` we can do a synchronous import
|
// Import our JS shim and initialize it, executing the start function when it's
|
||||||
// here!
|
// ready.
|
||||||
import { run } from './pkg/wasm2js';
|
import init from './pkg/wasm2js.js';
|
||||||
run();
|
init();
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
"scripts": {
|
|
||||||
"build": "webpack",
|
|
||||||
"serve": "webpack-dev-server"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"text-encoding": "^0.7.0",
|
|
||||||
"html-webpack-plugin": "^3.2.0",
|
|
||||||
"webpack": "^4.29.4",
|
|
||||||
"webpack-cli": "^3.1.1",
|
|
||||||
"webpack-dev-server": "^3.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,7 +7,7 @@ extern "C" {
|
|||||||
fn log(s: &str);
|
fn log(s: &str);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen(start)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
log("Hello, World!");
|
log("Hello, World!");
|
||||||
}
|
}
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
const path = require('path');
|
|
||||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
||||||
const webpack = require('webpack');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
entry: './index.js',
|
|
||||||
output: {
|
|
||||||
path: path.resolve(__dirname, 'dist'),
|
|
||||||
filename: 'index.js',
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
template: "index.html"
|
|
||||||
}),
|
|
||||||
// Have this example work in Edge which doesn't ship `TextEncoder` or
|
|
||||||
// `TextDecoder` at this time.
|
|
||||||
new webpack.ProvidePlugin({
|
|
||||||
TextDecoder: ['text-encoding', 'TextDecoder'],
|
|
||||||
TextEncoder: ['text-encoding', 'TextEncoder']
|
|
||||||
})
|
|
||||||
],
|
|
||||||
mode: 'development'
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user