Rax MiniApp Babel Plugins
raw JSON → 0.2.0 verified Sat Apr 25 auth: no javascript maintenance
A collection of Babel plugins for optimizing Rax mini-program (MiniApp) applications, version 0.2.0. These plugins enable pre-compilation analysis to determine used lifecycle methods, built-in components, and native/npm components, reducing runtime overhead and eliminating dead code. Part of the Rax MiniApp ecosystem, maintained for Alibaba-affiliated mini-program platforms. Key differentiator: performance optimization via compile-time introspection, avoiding full lifecycle registration and component tree traversal common in alternative solutions. Last updated 2022-05-17, with maintenance focused on bug fixes (event handling, WeChat map component).
Common errors
error Error: Cannot find module 'rax-miniapp-babel-plugins' ↓
cause Package not installed or incorrectly referenced in babel.config.js.
fix
Run
npm install rax-miniapp-babel-plugins --save-dev and ensure path is correct. error Plugin/Preset files are not allowed to export objects, only functions. ↓
cause Using a default export different from CommonJS require; Babel expects a function.
fix
Use
require('rax-miniapp-babel-plugins').NativeLifeCycle instead of require('rax-miniapp-babel-plugins') directly. error TypeError: Cannot read property 'NativeLifeCycle' of undefined ↓
cause Package exports incorrect structure; possibly due to version mismatch.
fix
Ensure version >=0.2.0; if not, update package. Check package.json "main" field.
Warnings
breaking Requires Babel 7+; not compatible with Babel 6. ↓
fix Upgrade to Babel 7 and use version 0.2.0 of this package.
deprecated Plugin configuration may be replaced by higher-level Rax CLI tools; manual Babel setup discouraged. ↓
fix Consider using `rax-miniapp-runtime-webpack-plugin` instead for automated configuration.
gotcha Plugins must be applied in order: first NativeLifeCycle, then UsedBuiltInComponents. ↓
fix Ensure the plugins array order in babel.config.js matches documentation.
gotcha Only supports Alibaba-affiliated mini-program platforms (WeChat, ByteDance, Baidu, Kuaishou, Alipay); not for generic web or Node.js. ↓
fix Verify your target platform is supported; if not, seek alternative optimization methods.
breaking NativeLifeCycle plugin expects lifecycle names in camelCase; incorrect casing fails silently. ↓
fix Use standard Rax lifecycle names: `onShow`, `onHide`, `onLoad`, etc.
Install
npm install rax-miniapp-babel-plugins yarn add rax-miniapp-babel-plugins pnpm add rax-miniapp-babel-plugins Imports
- default
const plugin = require('rax-miniapp-babel-plugins') - NativeLifeCycle wrong
import { NativeLifeCycle } from 'rax-miniapp-babel-plugins'correctconst { NativeLifeCycle } = require('rax-miniapp-babel-plugins') - UsedBuiltInComponents wrong
const UsedBuiltInComponents = require('rax-miniapp-babel-plugins').UsedBuiltInComponentscorrectconst { UsedBuiltInComponents } = require('rax-miniapp-babel-plugins')
Quickstart
// babel.config.js
module.exports = {
plugins: [
[require('rax-miniapp-babel-plugins').NativeLifeCycle, {}],
[require('rax-miniapp-babel-plugins').UsedBuiltInComponents, {}],
],
};