INNER CODE UNIT · TypeScript
rewriteIndexHtml
gimlet-io/capacitor · bundle.ts:55
async function rewriteIndexHtml({ jsFileName, cssFileName }: { jsFileName: string | null; cssFileName: string | null }): Promise<void> {
const indexPath = "bundle/index.html";
let html = await Deno.readTextFile(indexPath);
if (jsFileName) {
html = html.replace(/src="js\/[^"]+\.js"/g, `src="js/${jsFileName}"`);
}
if (cssFileName) {
html = html.replace(/href="styles\/[^"]+\.css"/g, `href="styles/${cssFileName}"`);
}
await Deno.writeTextFile(indexPath, html);
}
// Ensure bundle/ exists and copy static assets from public/ to bundle/
async function copyDir(src: string, dest: string): Promise<void> {
await Deno.mkdir(dest, { recursive: true });