0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/integrations/image/wasmize.mjs
2023-03-23 16:03:49 +00:00

13 lines
507 B
JavaScript

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)));
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');
}