Skip to content

Command Line ​

janja-cli compiles templates ahead of time into ES modules, so nothing is parsed or compiled when your application runs.

Installation ​

bash
pnpm add -D janja-cli

Compile Command ​

bash
# a single file
janja compile template.janja ./compiled

# every .janja and .html file of a directory
janja compile ./templates ./compiled --recursive

Options:

  • -r, --recursive: Also compile templates in subdirectories (the directory layout is kept)
  • --runtime: Also export a ready-to-call render(data, options) function
  • --source-map: Write a source map next to each compiled module
  • --dts: Write TypeScript declarations for each compiled module

{{ include "partials/footer" }} is resolved relative to the input directory, with or without the file extension, and is inlined into the compiled module. Compilation fails with a non-zero exit code when a template has errors.

Watch Command ​

Compiles once, then recompiles whenever a template is added, changed or removed:

bash
janja watch ./templates ./compiled --recursive

Check Command ​

Validate templates without compiling them, for example in CI. Prints file:line:column for every problem and exits with a non-zero status when there are errors:

bash
janja check ./templates --recursive
janja check ./templates --recursive --strict   # unknown filters fail too

Format Command ​

Normalise the spacing inside tags ({{=name|upper}} becomes {{= name | upper }}). Text between tags is never touched, and a tag that cannot be parsed is left as written:

bash
janja format ./templates --recursive
janja format ./templates --recursive --check   # report only, for CI

Using Compiled Templates ​

typescript
import { renderCompiled } from 'janja';
import { script } from './compiled/page.js';

const html = await renderCompiled(script, { title: 'Hello' });

With --runtime the module's default export does this for you:

typescript
import render from './compiled/page.js';

const html = await render({ title: 'Hello' });

Released under the MIT License.