I'm searching a way of using Nunjucks with the htmlWebpackPlugin to generate some html files on webpack compiling.
What I achieved so far
I managed to actually generate HTML from nunjucks template files through the nunjucks-html-loader but looking a bit closer to the code of said loader, the render method is called without sending vars to the templates.
So, for now with the following plugin config, I generate HTML without dynamically inserted vars
new HtmlWebpackPlugin({
filename: path.join(__dirname, '/' + page.filename),
template: 'nunjucks-html-loader!assets/templates/' + page.name + '.njk'
})
What I tried
For a testing purpose, I tried some changes on the node_module itself (I know, I know...) and changed
html = template.render(nunjucksContext);
into
html = template.render(nunjucksContext, { globals: global.globals });
Trying to define global.globals
in my webpack.config.js
file but this crashes with the following error
ERROR in Error: Child compilation failed:
Module build failed: TypeError: parentFrame.push is not a function
which is beyond my comprehension.
What I want
Is to use an extendable template engine like nunjucks which allows me to structure my templates like the following
<html>
<!-- layout structure inherited from every template -->
</html>
Every page I make extends the layout and only overrides some blocks
What I try to avoid
Partials like for exemple
header file :
<html>
<!-- header layout -->
footer file
<!-- footer layout -->
</html>
Every page I make includes partials
So my question is : Is it even possible tu use a template engine supporting inheritance like nunjucks with the htmlWebpackPlugin or is it mandatory to use another one like ejs for exemple and chunking the layout into partials which I do not like?