Utilities and an initial webpack loader

This commit is contained in:
dcodeIO
2018-01-29 17:04:39 +01:00
parent 9e3b6f202d
commit 74498852f0
8 changed files with 113 additions and 2 deletions

13
lib/webpack/index.js Normal file
View File

@ -0,0 +1,13 @@
var base64 = require("@protobufjs/base64");
(module.exports = function(buffer) {
var data = base64.encode(buffer, 0, buffer.length);
var code = [
'var data = "' + data + '", wasm;',
'module.exports = function(options) {',
' if (!wasm) wasm = require("@assemblyscript/webpack/decode")(data);',
' return new WebAssembly.Instance(new WebAssembly.Module(wasm), options && options.imports || {}).exports;',
'};'
];
return code.join("\n");
}).raw = true;