A Webpack 5 loader that precompiles Nunjucks templates and integrates with html-webpack-plugin. It parses template AST to automatically resolve imports, filters, and extensions, avoiding the default Nunjucks precompilation global. Features a custom {% static %} tag for async asset handling with HMR support. Current stable version is 3.2.0. Maintained by the community with moderate release cadence (major versions for Webpack upgrades). Key differentiators: full compatibility with Webpack 5, dynamic asset resolution, and zero global pollution.
npm install simple-nunjucks-loaderVerified import paths — ran on the pinned version, not inferred.
Shows basic Webpack setup with simple-nunjucks-loader and html-webpack-plugin.
Replace `{{ static('path') }}` with `{% static 'path' %}` and `{% set var = static('path') %}` with `{% static 'path' as var %}`.Upgrade to Webpack 5, or use simple-nunjucks-loader@2.x for Webpack 4.
Use CommonJS module syntax for filter and extension files, or upgrade to v3+ where this is partly mitigated.
Install with `npm install --no-optional simple-nunjucks-loader` to skip glob dependency.
Always check if the return value is a Promise when using dynamic assets or async features: `const result = await tmpl(ctx)` or use `.then()`.
Avoid passing unsupported options to the loader; only pass valid Nunjucks `Environment` options like `jinjaCompat`, `searchPaths`, `assetsPath`, etc.
Add rule in webpack.config.js: { test: /\.njk$/, use: ['simple-nunjucks-loader'] }Set the `searchPaths` option in the loader config to the directory containing your templates: { loader: 'simple-nunjucks-loader', options: { searchPaths: ['./src/templates'] } }Replace `{{ static('path') }}` with `{% static 'path' %}` in your Nunjucks template.