Bundle browser script, add package exports, add sourcemaps

This commit is contained in:
Tomás Fox
2022-03-15 15:27:19 -03:00
parent ab5cfd8582
commit e447a242c7
13 changed files with 1028 additions and 80 deletions

27
scripts/replace.js Normal file
View File

@@ -0,0 +1,27 @@
const { readFile, writeFile } = require("fs/promises");
const { dirname, resolve } = require("path");
main();
async function main() {
const root = dirname(__dirname);
const wasmJsPath = resolve(root, "dist/ffprobe-wasm.mjs");
let content = await readFile(wasmJsPath, { encoding: "utf8" });
content = `\
import initWasmInstance from "./ffprobe-wasm.wasm";
const initWasm = (info) =>
initWasmInstance(info).then((exports) => ({ instance: { exports } }));
${content}`;
content = content.replace(`import.meta.url`, `''`);
content = content.replace(
`instantiateAsync().catch(readyPromiseReject)`,
`initWasm(info).then(receiveInstantiatedSource, readyPromiseReject)`
);
await writeFile(wasmJsPath, content, { encoding: "utf8" });
}