2023-10-02 18:36:06 +08:00
|
|
|
// See: https://esbuild.github.io/plugins/#webassembly-plugin
|
|
|
|
|
|
|
|
const esbuild = require("esbuild");
|
|
|
|
const path = require("node:path");
|
|
|
|
const fs = require("node:fs");
|
|
|
|
|
|
|
|
let wasmPlugin = {
|
|
|
|
name: "wasm",
|
|
|
|
|
|
|
|
setup(build) {
|
|
|
|
build.onResolve({ filter: /\.wasm$/ }, (args) => {
|
|
|
|
if (args.namespace === "wasm-stub") {
|
|
|
|
return {
|
|
|
|
path: args.path,
|
|
|
|
namespace: "wasm-binary",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.resolveDir === "") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
path: path.isAbsolute(args.path)
|
|
|
|
? args.path
|
|
|
|
: path.join(args.resolveDir, args.path),
|
|
|
|
namespace: "wasm-stub",
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
build.onLoad({ filter: /.*/, namespace: "wasm-stub" }, async (args) => {
|
|
|
|
return {
|
2023-12-14 19:00:36 +08:00
|
|
|
contents: `export { default } from ${JSON.stringify(args.path)};`,
|
2023-10-02 18:36:06 +08:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
build.onLoad({ filter: /.*/, namespace: "wasm-binary" }, async (args) => {
|
|
|
|
return {
|
|
|
|
contents: await fs.promises.readFile(args.path),
|
|
|
|
loader: "binary",
|
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
esbuild
|
|
|
|
.build({
|
|
|
|
logLevel: "warning",
|
|
|
|
bundle: true,
|
|
|
|
minify: true,
|
|
|
|
alias: {
|
2024-02-26 21:45:58 +08:00
|
|
|
util: "./node_modules/@zxing/text-encoding",
|
2023-10-02 18:36:06 +08:00
|
|
|
},
|
|
|
|
define: {
|
2024-08-05 17:35:26 +08:00
|
|
|
process: `{ "env": { "EMBER_ENV": "production" } }`,
|
2023-10-02 18:36:06 +08:00
|
|
|
},
|
|
|
|
external: ["fs", "path"],
|
2024-09-03 17:51:07 +08:00
|
|
|
entryPoints: ["./transpiler.js"],
|
2023-10-02 18:36:06 +08:00
|
|
|
plugins: [wasmPlugin],
|
|
|
|
})
|
|
|
|
.then(() => {});
|