# babel-preset-miniprogram

> 微信小程序 babel 构建环境预设

Latest version **1.0.5** (published 2025-02-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-preset-miniprogram
pnpm add babel-preset-miniprogram
yarn add babel-preset-miniprogram
bun add babel-preset-miniprogram
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2025-02-07 |
| First published | 2020-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | chyizheng |
| Maintainers | wechat-miniprogram |
| Keywords | babel, preset, miniprogram, preset-env |

## Links

- npm: https://www.npmjs.com/package/babel-preset-miniprogram
- Repository: https://github.com/wechat-miniprogram/babel-preset-miniprogram
- Issues: https://github.com/wechat-miniprogram/babel-preset-miniprogram/issues
- npm.io page: https://npm.io/package/babel-preset-miniprogram

## Dependencies (5)

- [semver](https://npm.io/package/semver.md) ^7.3.2
- [core-js-compat](https://npm.io/package/core-js-compat.md) ^3.40.0
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.26.7
- [miniprogram-compat](https://npm.io/package/miniprogram-compat.md) ^1.0.0
- [@babel/helper-plugin-utils](https://npm.io/package/@babel/helper-plugin-utils.md) ^7.10.4

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 1.0.5 (latest) — 2025-02-07
- 1.0.4 — 2025-02-06
- 1.0.3 — 2025-02-06
- 1.0.2 — 2024-10-24
- 1.0.1 — 2020-11-26
- 1.0.0 — 2020-11-26

## README

# babel-preset-miniprogram

微信小程序 babel 构建环境预设

## 安装

```bash
npm install --save-dev babel-preset-miniprogram
```

## 使用

```javascript
// babel.config.js
module.exports = {
  presets: [
    [
      'babel-preset-miniprogram',
      {
        wechatLibVersion: '2.14.0', // 指定小程序最低基础库版本
        useBuiltIns: 'usage', // 打入 Polyfill
        modules: 'cjs', // 将代码转义为 commonjs
      },
    ],
  ],
};
```

## 配置项

### `wechatLibVersion: string`
指定构建小程序的目标最低[基础库版本](https://developers.weixin.qq.com/miniprogram/dev/framework/client-lib/version.html)，可以在 [小程序管理页](https://mp.weixin.qq.com/) 【设置】-【基本设置】-【基础库最低版本设置】中设置你的小程序最低版本

其余配置项可直接使用 [`@babel/preset-env`配置项](https://babeljs.io/docs/en/babel-preset-env#options)

## 实现

由于小程序基础库版本会与小程序[运行环境](https://developers.weixin.qq.com/miniprogram/dev/framework/runtime/env.html)版本绑定，因此特定小程序基础库可能的运行环境是确定的。
该预设便是利用该信息，只将运行环境必要的转义和 Polyfill 设置给 `@babel/preset-env`，从而尽可能减少编译处理和小程序代码体积。

另外由于小程序基础库本身自带了一个 [Polyfill](https://developers.weixin.qq.com/miniprogram/dev/framework/runtime/js-support.html)，该预设也会避免打入不必要的 Polyfill。

---
_Source: https://npm.io/package/babel-preset-miniprogram · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
