Coder Social home page Coder Social logo

mubaidr / prerender-plugin Goto Github PK

View Code? Open in Web Editor NEW
15.0 3.0 4.0 1.54 MB

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

License: MIT License

JavaScript 100.00%
prerender single-page-applications webpack webpack4 nodejs spa prerender-plugin

prerender-plugin's Introduction

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

Option Type Required Default Description
source String Yes Path of the web application.
target String source Path to save generated content.
routes Array of Strings ['/'] Routes which will be pre-rendered.
capture.delay Integer 1000ms Time to wait before page capture.
capture.event String Custom event for page capture.
capture.selector String Wait until selected selector is available in the page before page capture.
postProcess Function (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:

  • If two or more capture optons are provided, page capture will occur on the earliest of the provided options.
  • If capture.event or capture.selector option is being used then capture.delay will act as timeout (default 10s).

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

prerender-plugin's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar imgbotapp avatar mubaidr avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

prerender-plugin's Issues

edge cases

  • you can use await page.goto(pageUrl, { waitUntil: "networkidle0" }); to catch page content after all activity finished
  • you also need to make sure state of the form elements saved stereobooster/react-snap#84
  • CSS-in-JS solutions work stereobooster/react-snap#76
  • remove blob: URLs from HTML, because they don't make sense in generated HTML

Implement options for the script

  • input/output directory
    - [ ] timeout for page load
  • optimize page loading
  • routes to pre-render
  • option to post-process output
  • Capture page after:
    • delay
    • custom event
    • on element existence

Package won't build

Thanks for working on revamping the prerender-spa-plugin!

Receiving the following error when I only require prerender-plugin in my webpack file:

async function process (compilation, done) {
      ^^^^^^^^
SyntaxError: Unexpected token function

Webpack plugin

  • Convert script to web-pack plugin format
  • Add options for webpack plugin
  • Publish script to npm

add examples for all options

It'd be great to have examples for all available options to see how they work. (Currently trying out the webpack plugin)

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

[Feature] Option for `delay` to take precedence over `event` to trigger prerendering

Thanks for the plugin! Working much smoother than prerender-spa-plugin so far.

Some of my pages don't trigger the capture event intentionally and would be great if the delay could take precedence over this. From experience and peeking at your code it looks like if the capture event is set then the delay will never trigger a prerender. Is this true?

If so, is this something you think this plugin would be interested in using?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.