WeChat MiniProgram CI Plugin
Extract the compilation module from WeChat Developer Tools to implement one-click npm build / preview / upload for Mini Programs.
Supports Cloud Native Build, GitHub Actions and other CI/CD platforms.
Before using:
- Access WeChat Public Platform → Development → Development Settings with administrator privileges
- Download the code upload key
- Configure IP whitelist (or disable whitelist restriction)
Specify execution mode via mode parameter. Multiple modes can be separated by commas:
| Mode | Description |
|---|
upload | Upload code (default) |
preview | Preview and generate QR code |
packNpm | Build NPM |
packNpmManually | Manual NPM build |
getDevSourceMap | Get SourceMap |
| Parameter | Required | Description |
|---|
appid | ✓ | MiniProgram AppID |
projectPath | ✓ | Project path (directory containing project.config.json) |
privateKeyPath | ✓* | Private key file path |
privateKey | ✓* | Private key content (alternative to privateKeyPath) |
type | | Project type: miniProgram / miniProgramPlugin / miniGame / miniGamePlugin, default miniProgram |
ignores | | File exclusion rules, comma-separated, e.g. test/**/*,docs/**/* |
| Parameter | Required | Description |
|---|
version | Required for upload | Version number |
desc | | Version description |
robot | | CI robot number (1-30) |
threads | | Compilation thread count |
| Parameter | Description |
|---|
qrcodeFormat | QR code format: image / base64 / terminal, default image |
qrcodeOutputDest | QR code save path, default ./qrcode.jpg |
pagePath | Preview page path |
searchQuery | Preview page launch parameters |
scene | Scene value, default 1011 |
| Parameter | Description |
|---|
es6 | ES6 to ES5 |
es7 | Enhanced compilation |
minify | Minify all code |
minifyJS | Minify JS |
minifyWXML | Minify WXML |
minifyWXSS | Minify WXSS |
codeProtect | Code protection |
autoPrefixWXSS | Auto-prefix WXSS |
| Parameter | Description |
|---|
packNpmIgnores | Package names to exclude during npm build, comma-separated |
packageJsonPath | Required for packNpmManually, path to package.json |
miniprogramNpmDistDir | Required for packNpmManually, build output directory |
| Parameter | Description |
|---|
uploadResultOutputDest | Upload result save path |
sourceMapSavePath | SourceMap save path (required for getDevSourceMap) |
Usage on Cloud Native Build
main:
push:
- stages:
- name: miniprogram-ci
image: tencentcom/miniprogram-ci
settings:
mode: upload
appid: wxsomeappid
projectPath: ./
privateKeyPath: ./private.wxsomeappid.key
version: v1.0.0
desc: CI auto upload
es6: true
minify: true
main:
push:
- stages:
- name: miniprogram-ci
image: tencentcom/miniprogram-ci
settings:
mode: packNpm,upload
appid: wxsomeappid
projectPath: ./
privateKeyPath: ./private.wxsomeappid.key
version: v1.0.0
main:
push:
- stages:
- name: miniprogram-ci
image: tencentcom/miniprogram-ci
settings:
mode: preview
appid: wxsomeappid
projectPath: ./
privateKeyPath: ./private.wxsomeappid.key
qrcodeOutputDest: ./preview-qrcode.jpg
name: CI
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Upload MiniProgram
uses: docker://tencentcom/miniprogram-ci:latest
env:
PLUGIN_MODE: upload
PLUGIN_APPID: wxsomeappid
PLUGIN_PROJECTPATH: ./
PLUGIN_PRIVATEKEY: ${{ secrets.MINIPROGRAM_PRIVATE_KEY }}
PLUGIN_VERSION: v1.0.0
PLUGIN_DESC: CI auto upload
PLUGIN_ES6: true
PLUGIN_MINIFY: true
- name: Upload MiniProgram
uses: docker://tencentcom/miniprogram-ci:latest
env:
PLUGIN_APPID: wxsomeappid
PLUGIN_PROJECTPATH: ./
PLUGIN_PRIVATEKEYPATH: ./private.wxsomeappid.key
PLUGIN_VERSION: v1.0.0
- Log in to WeChat Public Platform
- Go to Development → Development Management → Development Settings → MiniProgram Code Upload
- Download the code upload key
- If you encounter IP whitelist issues, you can disable the whitelist restriction