Pug CLI
raw JSON → 1.0.0-alpha6 verified Sat Apr 25 auth: no javascript
Command-line interface for Pug (formerly Jade) template engine, version 1.0.0-alpha6. Allows compiling .pug files to HTML or client-side JavaScript. Supports watching, pretty-printing, custom output directories, and options via JSON/JS files. Primarily used for build tooling and static site generation. Maintained as part of the Pug project, though the CLI is in alpha with infrequent releases. Alternatives include gulp-pug or webpack loaders for integrated workflows.
Common errors
error pug: command not found ↓
cause pug-cli is not installed globally
fix
npm install -g pug-cli
error Cannot find module 'pug' ↓
cause pug package is not installed locally or globally
fix
npm install pug
error ENOENT: no such file or directory ↓
cause Output directory does not exist
fix
Create output directory: mkdir -p <outdir>
error SyntaxError: Unexpected token } in JSON ↓
cause Invalid JSON string passed to -O
fix
Use valid JSON with double quotes: pug -O '{"key": "value"}' file.pug
Warnings
gotcha When using --client, the output is a JavaScript function, not HTML. You need to include the Pug runtime. ↓
fix Use --client only for client-side compilation, and include pug-runtime in your project.
deprecated The --name-after-file option may be removed in future versions. ↓
fix Use --name explicitly instead.
gotcha Output directory is not created automatically if it doesn't exist; pug-cli will error. ↓
fix Ensure output directory exists before running, or use mkdirp.
gotcha The -O option with JSON string must be a valid JSON object, not a JavaScript object literal with single quotes. ↓
fix Use double quotes for JSON: pug -O '{"key": "value"}' file.pug
gotcha When using watch mode, only changes to files with .pug extension trigger re-render. Other file changes are ignored. ↓
fix Ensure all template files have .pug extension.
Install
npm install pug-cli yarn add pug-cli pnpm add pug-cli Imports
- pug command wrong
pug -c file.pug (without --client, outputs HTML)correctpug file.pug - require('pug') wrong
require('pug-cli')correctrequire('pug') - pug.compile() wrong
pug.compile() directly (missing require)correctconst pug = require('pug'); pug.compile('...')
Quickstart
npm install -g pug-cli
# Create a Pug template
echo 'h1 Hello #{name}' > template.pug
# Compile with variable
echo '{"name": "World"}' | pug -O /dev/stdin template.pug
cat template.html