Mpregular Template Compiler

raw JSON →
0.1.5 verified Fri May 01 auth: no javascript

Template compiler for mpregular, converting Regular.js templates into mini-program (WeChat/Alipay) compatible code. Version 0.1.5, with low release cadence and limited community adoption. Key differentiator: bridges Regular.js components to mini-program environments, unlike other tools that target Vue or React.

error Cannot find module 'mpregular-template-compiler'
cause Package not installed or import path incorrect in Node.js environment.
fix
Run 'npm install mpregular-template-compiler' and ensure using a bundler that supports ESM.
error TypeError: compile is not a function
cause Importing default instead of named export.
fix
Use 'import { compile } from ...' instead of 'import compile from ...'.
error result.code is undefined
cause Using old assumption that compile returns a string directly.
fix
Access result.code after compile returns an object.
gotcha The compile function expects template options, but if options are omitted, defaults may produce unexpected output.
fix Always pass an options object with 'type' and 'mode' explicitly.
breaking In version 0.1.0, the compile function returned a string; in 0.1.5 it returns an object with 'code' property.
fix Access result.code instead of treating result as a string.
deprecated The 'wx' type is deprecated in favor of 'wechat'.
fix Use type: 'wechat' instead of 'wx'.
gotcha The package only supports WeChat and Alipay mini-programs, not Baidu or Toutiao.
fix Check the documentation for supported platforms; for others, consider alternative compilers.
npm install mpregular-template-compiler
yarn add mpregular-template-compiler
pnpm add mpregular-template-compiler

Compiles a simple Regular.js template to WeChat mini-program code using the compile function.

import { compile } from 'mpregular-template-compiler';
const template = '<div>{{name}}</div>';
const result = compile(template, { type: 'wx', mode: 'component' });
console.log(result);