-
Notifications
You must be signed in to change notification settings - Fork 8
/
prerender.js
29 lines (25 loc) · 1.08 KB
/
prerender.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const fse = require('fs-extra')
const path = require('path')
const transformedTemplate = fse.readFileSync(
path.resolve(__dirname, 'dist/static/index.html'),
'utf-8'
)
const { Renderer } = require('./dist/server/entry-server.js')
const renderer = new Renderer(transformedTemplate)
Object.entries(renderer.pages).forEach(([pathname, page]) => {
const { body } = renderer.render(pathname)
const filePath = `dist/static${page.filePath}.html`
fse.outputFileSync(path.resolve(__dirname, filePath), body)
console.log('🖨 Prerendered', filePath)
})
Object.entries(renderer.feeds).forEach(([pathname, feed]) => {
const body = feed(renderer.pages)
const filePath = `dist/static${pathname}`
fse.outputFileSync(path.resolve(__dirname, filePath), body)
console.log('🖨 Prerendered', filePath)
})
console.log('🦖 Your static site is ready to deploy from dist/static')
const pkg = require('./package.json')
if (pkg.tropical.siteHost === 'https://www.example.org') {
console.log(`⚠️ Configure tropical.siteHost in package.json, otherwise links in your JSON Feed won't work!`)
}