Skip to content

Commit

Permalink
refactor: Avoid reparsing the HTML template
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Nov 19, 2023
1 parent b634ae6 commit 166aeb0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,12 @@ export function PrerenderPlugin({
globalThis.self = globalThis;

// Grab the generated HTML file, which we'll use as a template:
const tpl = (bundle["index.html"] as OutputAsset).source as string;
let htmlDoc = parse(tpl);
const bareTemplate = parse(
(bundle["index.html"] as OutputAsset).source as string,
);

// Create a tmp dir to allow importing & consuming the built modules, before
// Rollup writes them to the disk
// Create a tmp dir to allow importing & consuming the built modules,
// before Rollup writes them to the disk
const tmpDir = await fs.mkdtemp(
path.join(os.tmpdir(), "headless-prerender-"),
);
Expand Down Expand Up @@ -221,7 +222,7 @@ export function PrerenderPlugin({
if (result == null) continue;

// Reset HTML doc & head data
htmlDoc = parse(tpl);
const htmlDoc = bareTemplate;
head = { lang: "", title: "", elements: new Set() };

// Add any discovered links to the list of routes to pre-render:
Expand Down

0 comments on commit 166aeb0

Please sign in to comment.