nunjucks-webpack-plugin

raw JSON →
5.0.0 verified Sat Apr 25 auth: no javascript maintenance

A webpack plugin that compiles Nunjucks templates at build time. Version 5.0.0 (2018-11-12) supports webpack 2, 3, and 4, and drops Node.js 4. It renders .njk files with optional per-template context and writes outputs as webpack assets. Key differentiator: exposes webpack compilation hash (e.g., for cache busting) via __webpack__.hash in templates. Uses nunjucks ^3.0.0 as a peer dependency. Release cadence is low—last release was 2018; development appears inactive.

error Cannot find module 'nunjucks-webpack-plugin'
cause Missing installation of the plugin package.
fix
Run 'npm install --save-dev nunjucks-webpack-plugin'.
error You must provide an array of templates
cause The `templates` option was passed as an object (single template) instead of an array.
fix
Wrap the template object in an array: templates: [{ from: '...', to: '...' }].
error Option `template` is not supported. Did you mean `templates`?
cause Using the old option name `template` (singular) instead of `templates` (plural).
fix
Rename template to templates and ensure it is an array.
breaking Option `template` renamed to `templates` and must be an array. Single object no longer accepted.
fix Use `templates: [{ from: ..., to: ... }]` instead of `template: { from: ..., to: ... }`.
breaking Option `writeToFileWhenMemoryFs` renamed to `writeToFileEmit`.
fix Use `writeToFileEmit: true` instead of `writeToFileWhenMemoryFs: true`.
breaking Dropped support for webpack 1.
fix Upgrade to webpack 2, 3, or 4.
breaking Dropped support for Node.js 4.
fix Use Node.js >= 6.9.0.
gotcha In v4+, all templates are always emitted as webpack assets. Output files are written to disk only when `writeToFileEmit` is true or when not using webpack-dev-server.
fix Set `writeToFileEmit: true` per template to force writing to disk in memory-fs environments.
deprecated The package has had no releases since 2018. It may not support webpack 5 or newer Nunjucks versions.
fix Consider migrating to an actively maintained alternative (e.g., manually using nunjucks in a webpack loader).
npm install nunjucks-webpack-plugin
yarn add nunjucks-webpack-plugin
pnpm add nunjucks-webpack-plugin

Basic setup: compile a single Nunjucks template to an HTML output file via webpack.

import NunjucksWebpackPlugin from 'nunjucks-webpack-plugin';

export default {
  plugins: [
    new NunjucksWebpackPlugin({
      templates: [
        { from: 'src/template.njk', to: 'template.html' }
      ]
    })
  ]
};