-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pre-render the React app to HTML template
- Loading branch information
Showing
10 changed files
with
886 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
|
||
const distPath = path.resolve(import.meta.dirname, '../dist'); | ||
const prerendererPath = path.join(distPath, 'prerenderer/prerenderer.mjs'); | ||
const indexHtmlPath = path.join(distPath, 'client/index.html'); | ||
|
||
async function prerenderIndex() { | ||
const render = (await import(prerendererPath)).default; | ||
const prerenderedElement = render(); | ||
const indexHtml = await fs.readFile(indexHtmlPath, 'utf-8'); | ||
const resultHtml = indexHtml.replace(`<!-- pre-rendering placeholder -->`, () => prerenderedElement); | ||
await fs.writeFile(indexHtmlPath, resultHtml); | ||
} | ||
|
||
prerenderIndex(); |
Oops, something went wrong.