Is there a way to include partial using html-webpack-plugin?

serge1peshcoff picture serge1peshcoff · Feb 12, 2017 · Viewed 21.5k times · Source

I am using Webpack to compile my scripts and HTML (using html-webpack-plugin). The thing is, I have 5 HTML files that contains the same parts and I want to move these parts to separate .html files and then include these parts in every HTML file. This way, if I will change these smaller HTML files, it will recompile every HTML file to represent these changes.

Webpack does this for .js files by default, but can I use something like that for HTML files?

Answer

display name picture display name · Feb 13, 2017

You can use <%= require('html!./partial.html') %> in your template. Example here: https://github.com/jantimon/html-webpack-plugin/blob/master/examples/custom-template/template.html