build.mjs 543 B

1234567891011121314
  1. import { readFile, writeFile } from 'node:fs/promises';
  2. const directory = new URL('./', import.meta.url);
  3. const [template, styles, script] = await Promise.all(
  4. ['preview.template.html', 'styles.css', 'app.js'].map((name) =>
  5. readFile(new URL(name, directory), 'utf8'),
  6. ),
  7. );
  8. await writeFile(
  9. new URL('index.html', directory),
  10. template
  11. .replace('/* STYLES */', () => styles)
  12. .replace('/* SCRIPT */', () => script.replaceAll('</script', '<\\/script')),
  13. );
  14. console.log('Built standalone index.html (no network dependencies)');