Nunjucks loader module for webpack
npm install --save nunjucks-render-loader
module: {
rules: [
{
test: /\.njk$/,
use: {
loader: 'nunjucks-render-loader',
options: {
path: path.resolve(__dirname, 'src/views')
}
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: './index.njk'
})
]
module: {
rules: [
{
test: /\.njk$/,
use: {
loader: 'nunjucks-render-loader',
options: {
path: path.resolve(__dirname, 'src/views')
}
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
foo: 'bar',
filename: 'index.html',
template: './index.njk'
})
]
<!DOCTYPE html>
<html>
{% include "partials/_head.njk" %}
<body>
<%= htmlWebpackPlugin.options.foo %>
</body>
</html>
<!DOCTYPE html>
<html>
{% include "partials/_head.njk" %}
<body>
<img src="<%= require('./img/image.jpg') %>">
</body>
</html>
-
path
- Relative path to templates. (default: process.cwd()) -
context
- Data to pass to the template. (default: {}) -
envOptions
- These are options provided for nunjucks Environment. More info here. (default: {})