html-webpack-alter-html-plugin

1.0.0 • Public • Published

Alter the HTML file programatically that html-webpack-plugin generates

Enhances html-webpack-plugin functionality by allowing a webpack build to specify a function that alters the generated HTML.

This is an extension plugin for the webpack plugin html-webpack-plugin - a plugin that simplifies the creation of HTML files to serve your webpack bundles.

Installation

You must be running webpack on node 6.x or higher

Install the plugin with npm:

$ npm install --save-dev html-webpack-alter-html-plugin

Basic Usage

Require the plugin in your webpack config:

var HtmlWebpackAlterHtmlPlugin = require('html-webpack-alter-html-plugin');

Add the plugin to your webpack config as follows:

plugins: [
  new HtmlWebpackPlugin(),
  new HtmlWebpackAlterHtmlPlugin(alterHTML)
]  

alterHTML is a function that will be called during build with the HTML file generated by html-webpack-plugin. You can alter the HTML in the function and return the updated string. For example:

function alterHTML(html) {
	var $ = cheerio.load(html, {
		decodeEntities: false
	});
	
	// Alter the HTML.

	return $.html();
}

This plugin is based on html-webpack-harddisk-plugin.

License

Copyright (c) 2017 PointSource, LLC. MIT Licensed.

Package Sidebar

Install

npm i html-webpack-alter-html-plugin

Weekly Downloads

53

Version

1.0.0

License

MIT

Last publish

Collaborators

  • asselin