Home

Awesome

prerender-plugin

NPM

Node.js/webpack module/plugin to prerender static HTML in a single-page application.

What is Prerendering?

Prerendering is a process to preload all elements on the page in preparation for a web crawler to see it. If you’re using a Single Page Application (SPA) for a site that’s not behind a login and SEO is an important concern then this plugin could help you easily generate pre-rendered version of your application.

Installation

npm install prerender-plugin

Usage

This package can be used either directly with Node.js or with webpack build process.

Node.js

var PrerenderPlugin = require('prerender-plugin')
new PrerenderPlugin(options).apply()

Webpack

// webpack.config.js or webpack.prod.conf.js
var PrerenderPlugin = require('prerender-plugin')

module.exports = {
  // ...
  plugins: [
    // ...
    new PrerenderPlugin(options)
  ]
}

Options

OptionTypeRequiredDefaultDescription
sourceStringYesPath of the web application.
targetStringsourcePath to save generated content.
routesArray of Strings['/']Routes which will be pre-rendered.
capture.delayInteger1000msTime to wait before page capture.
capture.eventStringCustom event for page capture.
capture.selectorStringWait until selected selector is available in the page before page capture.
postProcessFunction (content, route)A function to process the generated HTML content. This function must return the final processed content. Content & route are the only parameters for this function

Notes:

Examples

Plese check the examples folder in the root directory for both Node.js and Webpack usage.

Development of this plugin is inspired by prerender-spa-plugin