Files
wasm/scripts/build-package.sh
T
Jaco Greeff da946b18ce Cleanup build, no sed mangling (#129)
* Polyfill require adjust

* Assert in promise for getRandomBytes

* Adjust jest

* Revert explicit overrides (from base)

* use typeof

* Re-add crypto-polyfill (backwards, direct imports)

* crypto log

* Fix dev

* Adjust

* Cleanups, no sed mangling

* Cleanup build folder

* Remove exports

* Cleanups

* Adjust env vs util

* Remove Buffer alloc

* Cleant ext vs int

* Rework naming

* Mapping rename

* Combine index & exports

* withWasm wrapper

* pass{String, U8a} -> alloc{String, U8a}

* Internal reuse

* Explict package-only test
2020-11-02 16:39:54 +01:00

46 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Copyright 2019-2020 @polkadot/wasm authors & contributors
# This software may be modified and distributed under the terms
# of the Apache-2.0 license. See the LICENSE file for details.
set -e
WSM=pkg/wasm_bg.wasm
OPT=pkg/wasm_opt.wasm
ASM=build/wasm_asm.js
echo "*** Building package"
# cleanup old
echo "*** Cleaning old builds"
rm -rf ./build ./pkg
mkdir -p build
# build new via wasm-pack
echo "*** Building WASM output"
wasm-pack build --release --scope polkadot --target web
# optimise
echo "*** Optimising WASM output"
../../binaryen/bin/wasm-opt $WSM -Os -o $OPT
# convert wasm to base64 structure
echo "*** Packing WASM into baseX"
node ../../scripts/pack-wasm-base.js
# build asmjs version from the input (optimised) WASM
echo "*** Building asm.js version"
../../binaryen/bin/wasm2js --output $ASM $OPT
# cleanup the generated asm, converting to cjs
sed -i -e '/import {/d' $ASM
echo "const imports = require('./imports');
$(cat $ASM)" > $ASM
sed -i -e 's/{abort.*},memasmFunc/imports, memasmFunc/g' $ASM
sed -i -e 's/export var /module\.exports\./g' $ASM
# copy our package interfaces
echo "*** Copying package sources"
cp package.json build/
cp src/js/* build/