I am trying to include Header.html
and also footer.html
inside index.html
. Because I am going to use these two files as common for all the pages. As my research webpack is not allowing to import files as
<!--#include file="header.html"-->
I've tried in grunt i was working fine . But how to do in webpack
this is my webpack version details
"name": "webpack-boilerplate",
"version": "1.0.0",
here is what i tried... in my webpack.config.js file
{
test: /\.html$/,
loader: 'html-loader'
}
in my index.html file
<body>
require("html-loader!./file.html");
<div class="banner">
<h3>Banner 1</h3>
</div>
<div class="banner banner2">
<h3>Banner 2</h3>
</div>
</body>
and this not for react. This is only for website and normal html..
so how to do this?
html-webpack-plugin supports templating with variables.
You can define the variables in your
webpack.config.js
And put them in place in your index.html like so:
To load the header and footer from normal HTML files requires an additional step and we use the built in
fs
node package for this (you don't have to install it).Now when you run webpack your HTML file will be injected in the positions you specified with the content of your header and footer files.