npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@oukeye/wechat-mp-build-upload-tool

v1.0.0

Published

微信小程序自动化打包上传工具

Readme

微信小程序自动化打包上传工具

一个独立的微信小程序自动化构建和上传工具,支持批量构建、多环境配置,并自动上传到微信平台。

功能特性

  • 自动化构建:一键构建多个微信小程序
  • 自动上传:自动上传代码到微信平台,支持版本号和描述
  • 多配置管理:支持不同小程序使用不同的配置(AppID、环境变量等)
  • 批量处理:支持一次性处理多个小程序
  • 灵活配置:通过 JSON 文件管理配置,易于维护
  • 全局安装:作为 npm 全局工具安装,可在任何项目中使用

安装

使用 npm 全局安装:

npm install -g wechat-mp-build-upload-tool

安装完成后,你将获得三个全局命令:

  • mp-build-upload: 构建并上传
  • mp-build: 仅构建
  • mp-upload: 仅上传

快速开始

1. 准备配置文件

在你的项目根目录下创建一个 mp-configs 文件夹,并添加小程序配置文件(JSON 格式)。

my-project/
├── mp-configs/
│   ├── app-1.json
│   └── app-2.json
└── ...

2. 创建配置文件

例如 mp-configs/app-1.json

{
  "name": "我的小程序1",
  "appid": "xxxxxxx",
  "projectPath": "dist/build/mp-weixin",
  "version": "1.0.0",
  "desc": "自动上传",
  "env": {
    "VITE_API_URL": "https://api.example.com",
    "VITE_APP_TITLE": "My App"
  }
}

配置说明:

  • name: 小程序名称(日志显示用)
  • appid: 微信小程序 AppID
  • projectPath: 构建输出路径(相对于项目根目录的相对路径)
  • version: 上传版本号(可选,默认 1.0.0)
  • desc: 上传描述(可选,默认 "自动上传")
  • env: 环境变量对象,构建时会写入 .env.local

3. 运行命令

在项目根目录下运行:

# 构建并上传所有小程序
mp-build-upload

# 构建并上传指定小程序(配置文件的文件名,不含后缀)
mp-build-upload app-1

# 覆盖版本号和描述
mp-build-upload app-1 --version=1.1.0 --desc="修复已知问题"

# 仅构建(不上传)
mp-build app-1

# 仅上传(适用于已经构建好的情况)
mp-upload app-1

详细使用说明

命令行参数

mp-build-upload (构建并上传)

mp-build-upload [小程序名称...] [选项]

| 参数 | 说明 | 示例 | |------|------|------| | 小程序名称 | 指定要处理的配置名称(对应 JSON 文件名) | app-1 app-2 | | --version | 指定上传版本号(覆盖配置文件) | --version=1.2.0 | | --desc | 指定上传描述(覆盖配置文件) | --desc="功能更新" | | --help | 显示帮助信息 | --help |

mp-build (仅构建)

mp-build [小程序名称...] [选项]

| 参数 | 说明 | 示例 | |------|------|------| | 小程序名称 | 指定要处理的配置名称 | app-1 app-2 | | --help | 显示帮助信息 | --help |

mp-upload (仅上传)

mp-upload <小程序名称> [选项]

| 参数 | 说明 | 示例 | |------|------|------| | 小程序名称 | 指定要上传的配置名称 | app-1 | | --version | 指定上传版本号 | --version=1.2.0 | | --desc | 指定上传描述 | --desc="功能更新" |

环境变量覆盖

你也可以通过环境变量来覆盖版本号和描述(优先级:命令行参数 > 环境变量 > 配置文件):

# Linux/macOS
VERSION=2.0.0 DESC="大版本更新" mp-build-upload app-1

# Windows PowerShell
$env:VERSION="2.0.0"; $env:DESC="大版本更新"; mp-build-upload app-1

前置条件

1. 微信开发者工具

确保已安装微信开发者工具,并开启服务端口(设置 -> 安全设置 -> 服务端口 -> 打开)。

重要: 运行命令前,请确保微信开发者工具已启动并登录

2. 配置 CLI 路径(如需)

工具会自动在默认路径查找微信开发者工具 CLI。如果安装在非标准路径,请设置环境变量 WECHAT_CLI_PATH

  • Windows: C:\Program Files (x86)\Tencent\微信web开发者工具\cli.bat
  • macOS: /Applications/wechatwebdevtools.app/Contents/MacOS/cli
# 示例:设置自定义路径
export WECHAT_CLI_PATH="/path/to/cli"

项目结构要求

工具假设你的项目符合常规的 uni-app 或类似结构,关键在于配置文件中的 projectPath 要指向正确的构建输出目录。

my-project/
├── mp-configs/             # [必须] 存放小程序配置文件的目录
│   └── *.json
├── src/                    # 源代码
├── dist/                   # 构建输出
│   └── build/
│       └── mp-weixin/      # [配置] projectPath 应指向这里
└── ...

常见问题

1. 找不到配置文件

确保在当前执行命令的目录下存在 mp-configs 文件夹,且里面有 .json 结尾的配置文件。

2. 微信开发者工具未运行

上传功能依赖微信开发者工具 CLI,请确保工具已启动并登录。

3. 上传失败

  • 检查 AppID 是否正确且有权限。
  • 检查是否开启了代码上传白名单或 IP 限制。

许可证

MIT