Skip to content

Commit

Permalink
merge wasm and js glue in one chunck
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasso committed Apr 30, 2017
1 parent 1931c45 commit 30db182
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"parser": "babel-eslint",
"rules": {
"global-require": "off",
"object-shorthand": "off",
"no-mixed-operators": "off",
"no-plusplus": "off",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"scripts": {
"clean": "rimraf lib dist es .nyc_output compiled",
"compile": "mkdir -p compiled && npm run compile:cpp && npm run compile:asmjs && npm run compile:wasm",
"compile": "npm run clean && mkdir -p compiled && npm run compile:cpp && npm run compile:asmjs && npm run compile:wasm",
"compile:cpp": "emcc -O3 -Wall -Werror --bind src/app.cpp -o compiled/asm-dom.bc && emcc -O3 -Wall -Werror --bind src/app.cpp -o compiled/asm-dom.o",
"compile:asmjs": "mkdir -p compiled/asmjs && emcc -O3 --bind --memory-init-file 0 --llvm-lto 3 --closure 1 --pre-js src/helpers/prefix.js --post-js src/helpers/postfix.js -s \"EXPORTED_RUNTIME_METHODS=['Pointer_stringify']\" -s AGGRESSIVE_VARIABLE_ELIMINATION=1 -s ELIMINATE_DUPLICATE_FUNCTIONS=1 -s ABORTING_MALLOC=1 -s NO_EXIT_RUNTIME=1 -s NO_FILESYSTEM=1 -s DISABLE_EXCEPTION_CATCHING=2 compiled/asm-dom.bc -o compiled/asmjs/asm-dom.asm.js",
"compile:wasm": "mkdir -p compiled/wasm && emcc -O3 --bind --memory-init-file 0 --llvm-lto 3 --pre-js src/helpers/prefix.js --post-js src/helpers/postfix.js -s ALLOW_MEMORY_GROWTH=1 -s \"EXPORTED_RUNTIME_METHODS=['Pointer_stringify']\" -s AGGRESSIVE_VARIABLE_ELIMINATION=1 -s ELIMINATE_DUPLICATE_FUNCTIONS=1 -s ABORTING_MALLOC=1 -s NO_EXIT_RUNTIME=1 -s NO_FILESYSTEM=1 -s DISABLE_EXCEPTION_CATCHING=2 -s BINARYEN=1 -s \"BINARYEN_TRAP_MODE='allow'\" compiled/asm-dom.bc -o compiled/wasm/asm-dom.js",
Expand All @@ -28,7 +28,7 @@
"build:umd": "cross-env BABEL_ENV=commonjs webpack --env.prod src/index.js dist/asm-dom.js",
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
"build:compile": "npm run compile && npm run build",
"prepublish": "npm run clean && npm run check:src && npm run build",
"prepublish": "npm run check:src && npm run build",
"lint": "eslint src test build",
"precommit-msg": "echo 'Pre-commit checks...' && exit 0"
},
Expand Down
6 changes: 1 addition & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ export default (config) => {
config = config || {};
let result;
if ((config.useWasm || 'WebAssembly' in window) && !config.useAsmJS) {
result = import('../compiled/wasm/asm-dom.wasm')
.then((wasm) => {
config.wasmBinary = new Uint8Array(wasm);
})
.then(() => import('../compiled/wasm/asm-dom.js'));
result = import('./js/loadWasm').then(x => x.default(config));
} else {
result = import('../compiled/asmjs/asm-dom.asm.js');
}
Expand Down
7 changes: 7 additions & 0 deletions src/js/loadWasm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default config => (
Promise.resolve(require('../../compiled/wasm/asm-dom.wasm'))
.then((wasm) => {
config.wasmBinary = new Uint8Array(wasm);
})
.then(() => require('../../compiled/wasm/asm-dom.js'))
);
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = (env) => {
loaders: [{
test: /\.js$/,
loaders: ['babel-loader'],
exclude: [/node_modules/, /src\/helpers/, /asm\.js$/],
exclude: [/node_modules/, /src\/helpers/, /\.asm\.js$/],
},
{
test: /\.wasm$/,
Expand Down

0 comments on commit 30db182

Please sign in to comment.