I'm trying to include a header.html in my index.html, as a partial via html-loader but header.html is rendering as literal text instead of HTML. Using interpolate as mentioned here and here seems applicable to Webpack v2. I also noticed that the #interpolate hash in html-loader URL is not working; meaning interpolate is defunct as of Webpack v4? Webpack emits an error about an Invalid options object if I include options: { interpolate: true }
Tree
--dist
--node_modules
--src
----js
------index.js
----partials
------header.html
--templates
----index.html
--package.json
--webpack.config.json
webpack.config.json
const path = require("path"),
webpack = require('webpack'),
{ CleanWebpackPlugin } = require("clean-webpack-plugin"),
HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
mode: "development",
entry: {
index: "./src/js/index.js"
},
plugins: [
// new CleanWebpackPlugin(['dist/*']) for < v2 versions of CleanWebpackPlugin
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: "Home",
filename: "index.html",
template: "templates/index.html",
inject: true,
minify: true
})
],
devtool: "source-map",
devServer: {
contentBase: "./dist"
},
output: {
// filename: "[name].bundle.js",
filename: "[name].[contenthash].js",
path: path.resolve(__dirname, "dist"),
// publicPath: "/"
},
optimization: {
moduleIds: "hashed",
runtimeChunk: "single",
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: "vendors",
chunks: "all",
}
}
}
},
module: {
rules: [
{
test: /\.(html)$/,
loader: "html-loader",
options: {
minimize: true
}
}
]
}
}
index.html
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>
<%= require("html-loader!./src/partials/header.html") %>
</body>
</html>
Edit 1
So I figured that interpolate
doesn't work in v1.0.0 of html-loader
basis this answer
My next question would be what alternatives do I have in place of interpolate
in v1.0.0?