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

https://github.com/blueoakjs/html-webpack-alter-html-plugin

Alter the HTML file programatically that html-webpack-plugin generates
https://github.com/blueoakjs/html-webpack-alter-html-plugin

Last synced: about 1 year ago
JSON representation

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

Awesome Lists containing this project

README

          

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

Enhances [html-webpack-plugin](https://github.com/ampedandwired/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](http://webpack.github.io) plugin [html-webpack-plugin](https://github.com/ampedandwired/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:
```shell
$ npm install --save-dev html-webpack-alter-html-plugin
```

Basic Usage
-----------
Require the plugin in your webpack config:

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

Add the plugin to your webpack config as follows:

```javascript
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:

```javascript
function alterHTML(html) {
var $ = cheerio.load(html, {
decodeEntities: false
});

// Alter the HTML.

return $.html();
}
```

This plugin is based on [html-webpack-harddisk-plugin](https://github.com/jantimon/html-webpack-harddisk-plugin).

# License

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