Command Line
janja-cli compiles templates ahead of time into ES modules, so nothing is parsed or compiled when your application runs.
Installation
pnpm add -D janja-cliCompile Command
# a single file
janja compile template.janja ./compiled
# every .janja and .html file of a directory
janja compile ./templates ./compiled --recursiveOptions:
-r, --recursive: Also compile templates in subdirectories (the directory layout is kept)--runtime: Also export a ready-to-callrender(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:
janja watch ./templates ./compiled --recursiveCheck 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:
janja check ./templates --recursive
janja check ./templates --recursive --strict # unknown filters fail tooFormat 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:
janja format ./templates --recursive
janja format ./templates --recursive --check # report only, for CIUsing Compiled Templates
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:
import render from './compiled/page.js';
const html = await render({ title: 'Hello' });