INNER CODE UNIT · TypeScript

findHashedJsFromMetafile

gimlet-io/capacitor · bundle.ts:45

function findHashedJsFromMetafile(metafile: esbuild.Metafile | undefined): string | null {
    if (!metafile) return null;
    const outputs = metafile.outputs ?? {};
    const jsOutputs = Object.keys(outputs).filter((p) => p.startsWith("bundle/js/") && p.endsWith(".js"));
    // Prefer app-*.js, fallback to first js output
    const appOutput = jsOutputs.find((p) => /\bapp-[a-f0-9]{8}\.js$/.test(p)) || jsOutputs[0];
    if (!appOutput) return null;
    return appOutput.replace("bundle/js/", "");
}

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}"`);
    }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…