nunjucks-render-loader
Nunjucks loader module for webpack
Installation
npm install --save nunjucks-render-loader
Usage
webpack.config.js
module: rules: test: /\.njk$/ use: loader: 'nunjucks-render-loader' options: path: path plugins: filename: 'index.html' template: './index.njk'
Tips
- ### Passing variables using HTML Webpack Plugin
webpack.config.js
module: rules: test: /\.njk$/ use: loader: 'nunjucks-render-loader' options: path: path plugins: foo: 'bar' filename: 'index.html' template: './index.njk'
index.njk
<!DOCTYPE html> {% include "partials/_head.njk" %} <%= htmlWebpackPlugin.options.foo %>
- ### Require images
<!DOCTYPE html> {% include "partials/_head.njk" %}
Options
-
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: {})