JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 34101
  • Score
    100M100P100Q154720F
  • License MIT

Minimal, unopinionated static site generator powered by webpack

Package Exports

  • static-site-generator-webpack-plugin

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (static-site-generator-webpack-plugin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

npm

static site generator webpack plugin

Minimal, unopinionated static site generator powered by webpack.

Provide a series of paths to be rendered, and a matching set of correctly nested index.html files will be rendered in your output directy by executing your own custom, webpack-compiled render function.

This plugin works particularly well with isomorphic UI libraries like React and React Router since it allows you to prerender your routes to HTML at build time, without requiring a Node server in production.

Install

$ npm install --save-dev static-site-generator-webpack-plugin

Usage

webpack.config.js

var StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin');

module.exports = {

  entry: './render.js',

  output: {
    filename: 'render.js',
    path: 'dist',
    /* IMPORTANT!
     * You must compile a module that can
     * can be required in a Node context: */
    libraryTarget: 'umd'
  },

  plugins: [
    new StaticSiteGeneratorPlugin('render.js', ['/hello/', '/world/'], { locals... })
  ]

};

render.js

module.exports = function(locals, callback) {
  callback(null, '<html>...</html>');
};

locals

// The path currently being rendered
locals.path;

// An object containing all assets:
locals.assets;

// Any locals provided in your config are also available:
locals.hello === 'world';

React Router example

var React = require('react');
var Router = require('react-router');
var template = require('./template.ejs');

module.exports = function render(locals, callback) {

  Router.run(Routes, locals.path, function(Handler) {

    var html = template({
      html: React.renderToString(<Handler />),
      assets: locals.assets,
    });

    callback(null, html);

  });

};

License

MIT License