2020-03-31 13:19:53 +00:00
|
|
|
const wabt = require("wabt")();
|
2020-03-31 11:44:16 +00:00
|
|
|
const filename = "module.wast";
|
|
|
|
|
2021-03-17 12:28:27 +00:00
|
|
|
export default function loader(source: string | Buffer): string | Buffer | void | undefined {
|
2020-03-31 11:44:16 +00:00
|
|
|
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 11:44:16 +00:00
|
|
|
|
2020-03-31 13:19:53 +00:00
|
|
|
this.callback(null, `module.exports = new Uint8Array([${buffer.join(",")}]);`);
|
2020-03-31 11:44:16 +00:00
|
|
|
}
|