Installation
The 4less binary is available after installing the package:
npm install @dzhonragon/4less
Add to package.json scripts or run via npx:
npx 4less --help
Synopsis
4less [options] [file]
Options
| Flag | Short | Description |
|---|---|---|
--eval | -e | Compile inline 4less code and print to stdout |
--output | -o | Write output to a file instead of stdout |
--watch | -w | Watch file for changes and recompile on save |
--format | -f | Output format: html (default), react, vue, astro, json |
--version | -v | Print version and exit |
--help | -h | Show help and exit |
Examples
Compile inline code and print to stdout:
4less -e 'h1 "Hello, world"'
Compile a file to HTML (default):
4less template.4l
Compile to React and write to a file:
4less template.4l --format react --output src/Template.jsx
Compile to Vue:
4less template.4l --format vue --output src/Template.vue
Compile to Astro:
4less template.4l --format astro --output src/Template.astro
Compile to JSON (AST representation):
4less template.4l --format json
Watch mode — recompiles every time the file is saved:
4less src/page.4l --output dist/page.html --watch
Combine output file with watch and a specific format:
4less src/page.4l --format react --output src/Page.jsx --watch
Print from stdin:
echo 'h1 "Hello"' | 4less
Exit Codes
| Code | Meaning |
|---|---|
0 | Compilation succeeded |
1 | Parse error or invalid flag — details printed to stderr |