Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dgeibi/simple-prerender-webpack-plugin

Build Time Rendering with webpack and html-webpack-plugin
https://github.com/dgeibi/simple-prerender-webpack-plugin

html-webpack-plugin prerender webpack webpack-plugin

Last synced: 1 day ago
JSON representation

Build Time Rendering with webpack and html-webpack-plugin

Awesome Lists containing this project

README

        

# simple-prerender-webpack-plugin

[![version][version-badge]][package]

## Features

- Based on Promise
- Support dynamic import
- Sourcemap: to enable sourcemap just configure webpack with `devtool: source-map`
- Inject rendering result into html-webpack-plugin as `htmlWebpackPlugin.options.prerendered`

## Install

```sh
$ npm install webpack html-webpack-plugin@next
$ npm install simple-prerender-webpack-plugin
```

## Examples

- [examples](examples)
- [dgeibi/yarb](https://github.com/dgeibi/yarb)

## Usage

`webpack.config.js`:

```js
const SimplePrerenderWebpackPlugin = require('simple-prerender-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
entry: './src/index.js',

plugins: [
new HtmlWebpackPlugin({
filename: 'page1.html',
template: './src/template.ejs',
}),
new HtmlWebpackPlugin({
filename: 'page2.html',
template: './src/template.ejs',
}),
new SimplePrerenderWebpackPlugin({
// (optional) path to file which exports a prerender function
//
// defaults to './src/index.js'
entry: './src/ssr.js',

// (optional)
// : path to partial webpack config
// : partial webpack config
config: {
plugins: [],
externals: [],
entry: './src/ssr.js',
module: {},
},

// (optional): filename of output
filename: 'prerender.js',

// (optional):
chunkFilename: 'prerender.[id].js',

// (optional): , see `examples/multi-instance`
id: '',

// (optional): whether write output to disk
writeToDisk: false,

// (optional): opts passed to webpack-node-externals
// see also https://www.npmjs.com/package/webpack-node-externals
nodeExternalsOptions: {},
}),
],
}
```

`./src/template.ejs`:

```ejs



<%= htmlWebpackPlugin.options.title %>

<%= htmlWebpackPlugin.options.prerendered %>

```

`./src/ssr.js`:

```js
export default ({
outputName, // html filename
plugin, // html-webpack-plugin instance
assets, // html-webpack-plugin assets
compilation,
compiler,
}) => {
return `

${outputName}
`
}
```

## LICENSE

[MIT](LICENSE)

[version-badge]: https://img.shields.io/npm/v/simple-prerender-webpack-plugin.svg
[package]: https://www.npmjs.com/package/simple-prerender-webpack-plugin