Registry / web-framework / miniprogram-compiler

miniprogram-compiler

JSON →
library0.2.3jsnpmunverified

Node.js wrapper for WeChat Mini Program official compilers (wcc for WXML, wcsc for WXSS). Version 0.2.3 is the latest stable release. It enables compiling .wxml and .wxss files into JavaScript functions that can render virtual DOM or CSS strings. Compared to alternatives like @vant/weapp or raw CLI tools, this package provides a programmatic API suitable for server-side rendering or testing. Release cadence is low; limited to basic compilation use. Only for Node.js (CJS only).

npm install miniprogram-compiler
INSTALL
IMPORT
SIG · MINIPROGRAM-COMPIL
M
miniprogram-compiler
web-frameworkjavascriptv0.2.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

wxmlToJs
✓ const { wxmlToJs } = require('miniprogram-compiler');
✗ import { wxmlToJs } from 'miniprogram-compiler';
Package is CJS-only; ES import will fail.
wxssToJs
✓ const { wxssToJs } = require('miniprogram-compiler');
Also CJS-only. No default export.

Compiles a .wxml file into a virtual DOM generator using the provided project root.

const { wxmlToJs } = require('miniprogram-compiler'); const path = require('path'); const miniprogramProjectRoot = path.resolve('./test'); const compilerString = wxmlToJs(miniprogramProjectRoot); const compiler = new Function('global', compilerString); const $gwx = compiler({}); const generateFunc = $gwx('wxml/index.wxml'); const result = generateFunc({ message: 'Hello', list: [1, 2, 3] }); console.log(result);
miniprogram-compiler --version
Debug
Known issues
gotchaPackage is CJS-only; ES imports will fail.
fix
Use require() or configure bundler to handle CJS modules.
affects: >=0.1.0
gotchaThe first argument to wxmlToJs and wxssToJs must be an absolute path to the mini program project root directory.
fix
Use path.resolve() to provide an absolute path.
affects: >=0.1.0
gotchawxmlToJs and wxssToJs may throw if the project root does not exist or does not contain mini program files.
fix
Ensure the directory exists and contains valid project files.
affects: >=0.1.0
gotchaThe returned compiler string must be evaluated with a function constructor; not just required/imported.
fix
Use new Function('global', compilerString) and then invoke with an object.
affects: >=0.1.0
gotchaThe $gwx function expects file paths relative to the project root, not absolute paths.
fix
Pass relative paths like 'pages/index/index.wxml'.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: compilerString is not a function
Calling wxmlToJs result directly instead of wrapping in new Function.
fix
Use new Function('global', compilerString) to create a function.
TypeError: $gwx is not a function
The compiler evaluation didn't return a valid $gwx function (wrong project root or missing wxml files).
fix
Ensure the project root contains the expected files and that you called compiler({}) correctly.
Upgrade
Version history
0.2.3latest on npm
Audit
Dependencies
wccrequiredThe official wxml compiler from WeChat; this is a wrapper.
wcscrequiredThe official wxss compiler from WeChat; this is a wrapper.
Agent activity
7 hits · last 30 days
node
6
Bingbot
1
Resources
miniprogram-compiler — npm install miniprogram-compiler · libregistry