40 lines
1.5 KiB
JavaScript
40 lines
1.5 KiB
JavaScript
// canvaskit and onnxruntime resolve their wasm at runtime, not through the
|
|
// bundler, so the binaries have to be served assets. 20MB of wasm in the repo is
|
|
// worse than 20MB copied out of node_modules at build time (the Docker build
|
|
// stage does the same).
|
|
import { copyFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
import { dirname } from 'node:path';
|
|
|
|
const copies = [
|
|
['node_modules/canvaskit-wasm/bin/full/canvaskit.wasm', 'public/wasm/canvaskit.wasm'],
|
|
// onnxruntime-web's default entry (its own bundled glue) looks for the jsep
|
|
// build of the runtime in `env.wasm.wasmPaths`; that build carries both the
|
|
// WebGPU and the plain WebAssembly execution provider, so one file is enough.
|
|
[
|
|
'node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.wasm',
|
|
'public/wasm/ort/ort-wasm-simd-threaded.jsep.wasm',
|
|
],
|
|
[
|
|
'node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.jsep.mjs',
|
|
'public/wasm/ort/ort-wasm-simd-threaded.jsep.mjs',
|
|
],
|
|
[
|
|
'node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.wasm',
|
|
'public/wasm/ort/ort-wasm-simd-threaded.wasm',
|
|
],
|
|
[
|
|
'node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.mjs',
|
|
'public/wasm/ort/ort-wasm-simd-threaded.mjs',
|
|
],
|
|
];
|
|
|
|
for (const [from, to] of copies) {
|
|
if (!existsSync(from)) {
|
|
console.error(`missing ${from} — run npm install first`);
|
|
process.exit(1);
|
|
}
|
|
mkdirSync(dirname(to), { recursive: true });
|
|
copyFileSync(from, to);
|
|
console.log(`copied ${from} -> ${to}`);
|
|
}
|