astro/packages/integrations/image/wasmize.mjs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

14 lines
507 B
JavaScript
Raw Normal View History

import fastglob from 'fast-glob';
import { fileURLToPath } from 'node:url';
import * as fs from 'node:fs';
const result = await fastglob(fileURLToPath(new URL('./src/**/*.wasm', import.meta.url)));
2023-03-23 16:03:49 +00:00
for (const filepath of result) {
const buffer = await fs.promises.readFile(filepath);
const base64 = buffer.toString('base64');
const source = `export default Buffer.from(${JSON.stringify(base64)}, 'base64');`;
const outpath = filepath + '.ts';
await fs.promises.writeFile(outpath, source, 'utf-8');
}