Registry / web-framework / mpvue-template-compiler

mpvue-template-compiler

JSON →
library1.4.6jsnpmunverified

Template compiler for mpvue, a framework for building Mini Programs using Vue.js. Current stable version is 1.4.6. The compiler transforms Vue template syntax into target-specific code for WeChat, Alipay, Baidu, and Toutiao Mini Programs. Release cadence is irregular; ongoing maintenance on 1.x branch. Key differentiators: extends Vue syntax to Mini Programs, supports multiple platforms in 2.x. Requires mpvue-loader and mpvue core. Common issues arise from mismatched versioning between compiler and framework, and incorrect fileExt configuration.

npm install mpvue-template-compiler
INSTALL
IMPORT
SIG · MPVUE-TEMPLATE-COM
M
mpvue-template-compiler
web-frameworkjavascriptv1.4.6
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.

mpvueTemplateCompiler
const compiler = require('mpvue-template-compiler')
import compiler from 'mpvue-template-compiler'
Package does not provide ESM exports; use require for Node.js usage.
compile
const { compile } = require('mpvue-template-compiler')
import { compile } from 'mpvue-template-compiler'
Named export compile is available but only via require; ESM import may fail.
parseComponent
const { parseComponent } = require('mpvue-template-compiler')
import parseComponent from 'mpvue-template-compiler'
parseComponent is a named export, not default.

Demonstrates basic compilation of a mpvue template using require() and compile() with platform option.

const compiler = require('mpvue-template-compiler'); const template = '<view>{{ msg }}</view>'; const result = compiler.compile(template, { mpvue: true, platform: 'wx', // WeChat warn: false }); console.log(result.render); // Expected output: an object with render, staticRenderFns, errors, tips
Debug
Known issues
breakingVersion mismatch: mpvue-template-compiler must match mpvue version exactly; otherwise template compilation produces invalid code.
fix
Ensure mpvue-template-compiler version equals mpvue version in package.json.
affects: >=1.0.0
breakingFileExt configuration: In mpvue 2.x and 1.x builds, the fileExt option must be set in config for correct output.
fix
Add fileExt: { mp: '.wxml', wx: '.wxml' } (or appropriate platform extensions) in build config.
affects: >=1.4.0
deprecated2.x branch: mpvue 2.0 introduced multi-platform support; 1.x is still maintained but no new features.
fix
Upgrade to mpvue 2.x only if multi-platform support is needed; otherwise stick with 1.x.
affects: >=2.0.0
gotchaESM import not supported: This package uses CommonJS; using import may fail in some bundlers.
fix
Use require() or configure bundler to handle CJS interop.
affects: >=1.0.0
gotchaCompilation result includes errors and tips: Ignoring errors array leads to silent failures in production.
fix
Always check result.errors after compile() and log or throw on any errors.
affects: >=1.0.0
breakingPlatform option required in compile(): Omitting platform may generate wrong template for target mini program.
fix
Always specify platform: 'wx' | 'alipay' | 'baidu' | 'toutiao'.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: compiler.compile is not a function
Importing as ES module (import) but package only supports CommonJS.
fix
Change to const compiler = require('mpvue-template-compiler'); or use dynamic import with default export.
Module not found: Error: Can't resolve 'mpvue-template-compiler' in ...
Package not installed because it's a dependency of mpvue-loader and may not be in package.json.
fix
Run npm install mpvue-template-compiler --save-dev (or --save) to add it explicitly.
SyntaxError: Unexpected token 'import'
Using ES module syntax in a Node script without proper module setup.
fix
Set type: 'module' in package.json and use import syntax, or use require() with CommonJS.
Compilation error: Unknown platform 'wx'
Platform name mismatch: common mistake where platform value is incorrect (e.g., 'wechat' instead of 'wx').
fix
Use platform: 'wx' for WeChat, 'alipay' for Alipay, 'baidu' for Baidu, 'toutiao' for Toutiao.
ERROR: Must be used with mpvue-loader
Attempting to use compiled output directly without the loader or proper bundler setup.
fix
Ensure you have mpvue-loader installed and properly configured in webpack.
Upgrade
Version history
1.4.6latest on npm
Audit
Dependencies
mpvuerequiredRuntime peer dependency, version must match template-compiler.
mpvue-loaderoptionalRequired for bundling; mismatched versions cause compilation errors.
Agent activity
2 hits · last 30 days
node
2
Resources
mpvue-template-compiler — npm install mpvue-template-compiler · libregistry