1.0.2 • Published 2 years ago
site-prerender v1.0.2
Site Prerender
- prerender an SPA (react, vue, angular or whatever), for better SEO and first page load
Installation
npm install site-prerender --save
Usage
const SitePrerender = require('site-prerender')
const sp = new SitePrerender({
staticPath: '/my-project/dist,
outputFolder: '/my-project/output,
routes: ['/', '/about']
})
await sp.init()
await sp.start()
await sp.close()
How it works
- Build a temporary express server to serve the SPA.
- Use
puppeteer
to open a headless browser and crawl the pages based of routes config. - Get the HTML rendered in that headless browser
- Save it the destination
Example project
https://github.com/dattranone/markdown-vue-blog/blob/master/scripts/prerender.js