Registry / devops / nunjucks-minify-loaders

nunjucks-minify-loaders

JSON →
library1.0.2jsnpmunverified

A Nunjucks add-on (v1.0.2, latest) that passes template source through html-minifier before rendering. It wraps Nunjucks' built-in loaders (e.g., FileSystemLoader) to minify HTML output automatically. Different from standalone minification by integrating directly into the template loading pipeline. No active updates since initial release.

npm install nunjucks-minify-loaders
INSTALL
IMPORT
SIG · NUNJUCKS-MINIFY-LO
N
nunjucks-minify-loaders
devopsjavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FileMinifyLoader
import { FileMinifyLoader } from 'nunjucks-minify-loaders'
const { FileMinifyLoader } = require('nunjucks-minify-loaders')
Package exports only this class; named import required.
FileMinifyLoader
const { FileMinifyLoader } = require('nunjucks-minify-loaders')
const FileMinifyLoader = require('nunjucks-minify-loaders')
Correct CommonJS usage destructures the named export.
default
import nunjucksMinifyLoaders from 'nunjucks-minify-loaders'
import { default } from 'nunjucks-minify-loaders'
Default import not available; use named import.

Shows how to create a Nunjucks environment with a FileMinifyLoader that minifies templates using html-minifier options.

const nunjucks = require('nunjucks'); const { FileMinifyLoader } = require('nunjucks-minify-loaders'); const opts = { watch: true, noCache: false, minify: { removeComments: true, minifyJS: true, } }; const loader = new FileMinifyLoader('./views', opts); const env = new nunjucks.Environment(loader); // Templates from ./views will be minified const html = env.render('page.html', { title: 'Hello' }); console.log(html);
Debug
Known issues
gotchaThe library only supports FileSystemLoader from Nunjucks. Other loaders (e.g., WebLoader) are not wrapped.
fix
If you need other loaders, extend the class or use a different minification approach.
affects: >=1.0.0
gotchaThe html-minifier options must be passed in the 'minify' object; incorrect nesting will be silently ignored.
fix
Ensure options are under 'minify' key, e.g., { minify: { removeComments: true } }.
affects: >=1.0.0
gotchaThe package has no TypeScript type definitions; type safety is not provided.
fix
Use @types/nunjucks and define your own types or use plain JavaScript.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: FileMinifyLoader is not a constructor
Using default import instead of named import.
fix
Use const { FileMinifyLoader } = require('nunjucks-minify-loaders');
Error: Cannot find module 'html-minifier'
Missing required peer dependency html-minifier.
fix
Run npm install html-minifier --save
TypeError: loader.getSource is not a function
Passing an invalid loader class or options without a valid 'minify' object.
fix
Ensure first argument is a valid Nunjucks loader path or a loader instance, and options contain minify configuration.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
html-minifierrequireddependency for minifying HTML templates
nunjucksrequiredpeer dependency for the Nunjucks templating engine
Agent activity
2 hits · last 30 days
node
2
Resources
nunjucks-minify-loaders — npm install nunjucks-minify-loaders · libregistry