Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
html-webpack-jsdom-prerender-plugin
Advanced tools
Webpack plugin to prerender JS apps in a JSDOM context
A plugin to prerender and inject JavaScript apps into the static markup generated by html-webpack-plugin at build time. This was heavily inspired by html-webpack-prerender-plugin by Reuters Graphics.
Install this package and html-webpack-plugin
as dev dependencies
yarn add --dev html-webpack-plugin html-webpack-jsdom-prerender-plugin
Add the plugins to your webpack configuration
// webpack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin')
const HtmlWebpackJsdomPrerenderPlugin = require('html-webpack-jsdom-prerender-plugin')
module.exports = {
entry: './src/js/index.js',
output: {
path: './dist',
filename: '[name].js',
},
// ...
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/templates/index.html',
}),
new HtmlWebpackJsdomPrerenderPlugin({
'index.html': {
chunks: ['main'],
},
}),
],
}
Create an HTML template for your app
<!-- src/templates/index.html -->
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head></head>
<body>
<div id='root'></div>
</body>
</html>
Make sure your app will change the DOM when it runs. If you're using
a framework like React you can use the flag
window.__HTML_WEBPACK_JSDOM_PRERENDER_PLUGIN__
to see if your app is
running in a prerender environment rather than on the client.
// src/js/index.js
import React from 'react'
import { render } from 'react-dom'
import { renderToString } from 'react-dom/server'
import Component from './my-component'
const node = document.getElementById('root')
if (window.__HTML_WEBPACK_JSDOM_PRERENDER_PLUGIN__) {
node.innerHTML = renderToString(<Component />)
} else {
render(<Component />, node)
}
FAQs
Webpack plugin to prerender JS apps in a JSDOM context
The npm package html-webpack-jsdom-prerender-plugin receives a total of 0 weekly downloads. As such, html-webpack-jsdom-prerender-plugin popularity was classified as not popular.
We found that html-webpack-jsdom-prerender-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.