Skip to main content
After installing Wik/Lex via Composer, the lex binary is available at vendor/bin/lex. Use it to manage templates without writing PHP.
vendor/bin/lex <command>
The CLI reads your lex.config.json file automatically. Make sure it exists at the project root before running any command.

Commands

Recursively finds every .lex file under <path> and compiles it to a PHP file in the cache directory. Use this before enabling production mode so all compiled files are ready before the first request.
vendor/bin/lex compile views/
Arguments
ArgumentDescription
<path>Directory to scan recursively for .lex template files
Example: CI/CD deployment pipelineRun lex compile as a build step before switching the application to production mode. This ensures every template is precompiled and no source-file I/O happens at runtime.
# In your deploy script
composer install --no-dev --optimize-autoloader
vendor/bin/lex compile views/
# Now safe to set "production": true in lex.config.json
Deletes the compiled PHP files and AST snapshots from the cache directory. Forces a full recompile on the next request.
vendor/bin/lex cache:clear .lexer/
Arguments
ArgumentDescription
<dir>Cache directory to clear (typically .lexer/)
This removes all files under <dir>/compiled/ and <dir>/ast/, as well as the dependency graph at <dir>/view_dependencies.json.
Renders the specified template multiple times and reports the mean render time in milliseconds. Useful for identifying slow templates before they reach production.
vendor/bin/lex benchmark pages.home
Arguments
ArgumentDescription
<template>Dot-notation template name to benchmark (e.g. pages.home)
The command outputs a summary showing the number of iterations, mean time, minimum, and maximum render times.
Parses and validates every .lex file under <path> without rendering or writing any compiled output. Reports syntax errors, unmatched blocks, and unknown directives.
vendor/bin/lex validate views/
Arguments
ArgumentDescription
<path>Directory to scan recursively for .lex template files
Use this in CI pipelines to catch template errors before deployment, without touching the cache.
# Validate all templates as part of a CI check
vendor/bin/lex validate views/
echo "Templates OK"

CI/CD deployment workflow

A typical production deployment runs three steps in order:
1

Install dependencies

composer install --no-dev --optimize-autoloader
2

Validate templates

Catch any syntax errors before the cache is built.
vendor/bin/lex validate views/
3

Precompile templates

Write all compiled PHP files to the cache directory so no compilation happens at runtime.
vendor/bin/lex compile views/
4

Enable production mode

Set "production": true in lex.config.json, or call setProduction() in your bootstrap. Lex will serve every template directly from the precompiled index with zero recompilation overhead.
{ "production": true }

Build docs developers (and LLMs) love