nunjucks-cli
raw JSON → 1.0.0 verified Sat Apr 25 auth: no javascript
A CLI wrapper and file watcher for Nunjucks templates, enabling compilation of Nunjucks files to static HTML. Version 1.0.0, released as an initial stable version, works as a command-line tool for rendering templates with JSON data and watching for changes. Key differentiators: built-in watcher for automatic re-rendering, support for glob patterns, process.env injection as context, and sensible defaults like ignoring partials starting with underscore.
Common errors
error nunjucks: command not found ↓
cause Installed locally without global link or npx
fix
Use
npx nunjucks or install globally with npm i -g nunjucks-cli then run nunjucks. Warnings
gotcha Template files starting with underscore (_) are ignored by default ↓
fix Rename files without underscore or use a different tool if you need to compile underscore-prefixed templates.
Install
npm install nunjucks-cli yarn add nunjucks-cli pnpm add nunjucks-cli Imports
- nunjucks-cli wrong
npm install -g nunjucks-cli && nunjucks <file> [context] [options]correctnpx nunjucks <file> [context] [options]
Quickstart
# Create a sample template
echo 'Hello {{ name }}!' > hello.tpl
# Create a sample data file
echo '{"name": "World"}' > data.json
# Render the template to HTML
npx nunjucks hello.tpl data.json
# Output: hello.html with content 'Hello World!'
# Watch mode for auto-recompilation
npx nunjucks **/*.tpl --watch