TeaWeb/webpack/WatLoader.ts

11 lines
390 B
TypeScript
Raw Normal View History

2020-03-31 13:19:53 +00:00
const wabt = require("wabt")();
const filename = "module.wast";
export default function loader(source: string | Buffer): string | Buffer | void | undefined {
this.cacheable();
const module = wabt.parseWat(filename, source);
2020-03-31 13:19:53 +00:00
const { buffer } = module.toBinary({ write_debug_names: false });
2020-03-31 13:19:53 +00:00
this.callback(null, `module.exports = new Uint8Array([${buffer.join(",")}]);`);
}