This is a webpack plugin that provides a way to do simple HTML includes in your html files. The intended purpose is to add common snippets like headers, footers, sidebars, etc. into the html pages. It was originally designed for situations where a multi page website is being generated with webpack.
PLEASE NOTE: This plugin works in conjunjunction with html-webpack-plugin
How to use
First of all, you need both
npm install html-webpack-plugin html-webpack-simple-include-plugin
This plugin is designed to simply replace a search pattern with replacement text. I use fake html tags as the search pattern just in case something goes wrong. That way if the search text is not replaced the search text does not get displayed in the HTML file. For example ''
The plugin is passed an array of objects with
content properties. The HTML files get serached for the tag value and if found, get replaced with the content value.
html-replace-webpack-pluginIS PLACED AFTER
html-webpack-pluginin Webpack config.
const webpack =const HtmlWebpackSimpleIncludePlugin = ;const fs = ;moduleexports =// Webpack plugins. NOTE that HtmlWebpackSimpleIncludePlugin comes after HtmlWebpackPluginplugin:/* configurations */// Replace html contents with string or regex patterns// this example shows replacing with literal texttag: '<include-header />'content: '<h1>This is my header</h1>'// this example shows replacing with file contentstag: '<include-footer />'content: fs}
In your source HTML file(s):
My Web PageMain COntent
This project is licensed under the MIT License - see the LICENSE file for details