Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jeremyben/nunjucks-cli

Simple Nunjucks CLI wrapper and templates watcher
https://github.com/jeremyben/nunjucks-cli

cli npm nunjucks template-engine

Last synced: 7 days ago
JSON representation

Simple Nunjucks CLI wrapper and templates watcher

Awesome Lists containing this project

README

        

# Nunjucks-cli

Simple Nunjucks CLI Wrapper and templates watcher, to generate static HTML files.

## Installation

```bash
npm i -D nunjucks-cli # local
npm i -g nunjucks-cli # global
```

## Usage

```bash
nunjucks [context] [options]
```

_For convenience, `process.env` object is added to the context as `env`._

#### Basic examples

```bash
nunjucks foo.tpl data.json
```

Compiles `foo.tpl` to `foo.html` with data from `data.json` (and variables from `process.env` as `env`).

```bash
nunjucks **/*.tpl
```

Compiles all `.tpl` files (including subdirectories), except the ones starting by `_` (so you can use them as layouts).

## Options

### `--path `

`-p `

Path where the templates live. Default to the current working directory.
See

### `--out `

`-o `

Output directory.

### `--watch`

`-w`

Allows to keep track of file changes and render accordingly (except files starting by `_`).

### `--extension `

`-e `

Extension for rendered files. Defaults to `html`.

### `--options `

`-O `

Takes a json file as Nunjucks options. Defaults are :

```json
trimBlocks: true,
lstripBlocks: true,
noCache: true
```

See

#### Advanced examples

```bash
nunjucks foo.tpl -p src -o dist -O nj.json
```

Compiles `src/foo.tpl` to `dist/foo.html`, with `nj.json` as nunjucks environnement options.

```bash
nunjucks *.tpl data.json -w -p src
```

Compiles all `.tpl` files (except ones starting with `_`) in the `src` folder to the current working directory, with `data.json` as metadata, and keeps running in the background for files changes.