yox-template-compiler
raw JSON → 0.29.0 verified Fri May 01 auth: no javascript
A template compiler for Yox.js, transforming Yox templates into render functions. Version 0.29.0 is the current stable release, with a slow release cadence. It requires yox-common, yox-config, yox-type, and yox-expression-compiler as peer dependencies. Key differentiator: designed specifically for the Yox.js framework, not a general-purpose template engine.
Common errors
error Cannot find module 'yox-common' ↓
cause Missing peer dependency
fix
npm install yox-common@^0.20.0
error TypeError: compile is not a function ↓
cause Incorrect import: using default import instead of named
fix
Use import { compile } from 'yox-template-compiler'
Warnings
breaking The compile function returns a different structure in v0.29.0 vs v0.28.x ↓
fix Update code to handle new return shape: render function is now under .code
deprecated compileToString is deprecated since v0.25.0 ↓
fix Use compile or compileToFunctions instead
gotcha All peer dependencies must be at the exact versions specified; mismatch causes runtime errors ↓
fix Install exact versions: yox-common@^0.20.0, yox-config@^0.3.0, etc.
gotcha The compiler only works in Node.js; browser usage requires bundling ↓
fix Use a bundler like webpack or Rollup for browser builds
Install
npm install yox-template-compiler yarn add yox-template-compiler pnpm add yox-template-compiler Imports
- compile wrong
const compile = require('yox-template-compiler').compilecorrectimport { compile } from 'yox-template-compiler' - compileToFunctions wrong
import compileToFunctions from 'yox-template-compiler'correctimport { compileToFunctions } from 'yox-template-compiler' - CompileOptions
import type { CompileOptions } from 'yox-template-compiler'
Quickstart
import { compile } from 'yox-template-compiler';
const template = '<div>{{ message }}</div>';
const result = compile(template);
console.log(result);