zfml-transpiler
raw JSON → 1.0.6 verified Fri May 01 auth: no javascript
A template compiler for ZFML (WeChat WXML-like syntax) that compiles .wxml files into JavaScript render functions. Version 1.0.6 is the latest stable release, with no clear release cadence. It mimics the behavior of wcc.exe/wcc used in WeChat Mini Programs. Key differentiators: lightweight, Node.js-based alternative to the official wcc compiler, focused on transforming WXML templates for WeChat ecosystem development. Maintained as a single-function library with minimal dependencies.
Common errors
error Error: ENOENT: no such file or directory, open '...' ↓
cause Relative file path provided to wxmlCompile instead of absolute.
fix
Use path.resolve(__dirname, './relative/path/to/file.wxml') to convert to absolute path.
error TypeError: compiler.wxmlCompile is not a function ↓
cause Using ESM import which returns a module with only default export; the function is actually on the module exports object.
fix
Use require('zfml-transpiler') or require('zfml-transpiler').wxmlCompile.
error Error: Invalid file list: expected an array ↓
cause Passing a single file path string instead of an array.
fix
Wrap the file path in an array: wxmlCompile(['file.wxml']) or pass an array of paths.
Warnings
gotcha File paths must be absolute; relative paths cause silent failures or incorrect output. ↓
fix Use path.resolve() or absolute paths for each .wxml file in the fileList array.
breaking Output format changed from string to object in v1.0.0. ↓
fix Update code to handle an object with a 'js' property instead of a raw string.
deprecated Use wxmlCompile instead of compile; compile() will be removed in v2.0.0. ↓
fix Replace compiler.compile() with compiler.wxmlCompile().
Install
npm install zfml-transpiler yarn add zfml-transpiler pnpm add zfml-transpiler Imports
- compiler wrong
import compiler from 'zfml-transpiler'correctconst compiler = require('zfml-transpiler') - wxmlCompile wrong
import { wxmlCompile } from 'zfml-transpiler'correctconst { wxmlCompile } = require('zfml-transpiler') - default import wrong
import compiler from 'zfml-transpiler'correctconst compiler = require('zfml-transpiler')
Quickstart
const compiler = require('zfml-transpiler');
const path = require('path');
const fileList = [
path.resolve(__dirname, './pages/index/index.wxml'),
path.resolve(__dirname, './common/head.wxml'),
path.resolve(__dirname, './common/foot.wxml')
];
try {
const result = compiler.wxmlCompile(fileList);
console.log('Compiled JS:', result);
} catch (err) {
console.error('Compilation failed:', err);
}