logo
6
3
WeChat Login

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.

Prerequisites

Before using:

  1. Access WeChat Public Platform → Development → Development Settings with administrator privileges
  2. Download the code upload key
  3. Configure IP whitelist (or disable whitelist restriction)

Supported Modes

Specify execution mode via mode parameter. Multiple modes can be separated by commas:

ModeDescription
uploadUpload code (default)
previewPreview and generate QR code
packNpmBuild NPM
packNpmManuallyManual NPM build
getDevSourceMapGet SourceMap

Parameters

Basic Parameters

ParameterRequiredDescription
appidMiniProgram AppID
projectPathProject path (directory containing project.config.json)
privateKeyPath✓*Private key file path
privateKey✓*Private key content (alternative to privateKeyPath)
typeProject type: miniProgram / miniProgramPlugin / miniGame / miniGamePlugin, default miniProgram
ignoresFile exclusion rules, comma-separated, e.g. test/**/*,docs/**/*

Task Parameters

ParameterRequiredDescription
versionRequired for uploadVersion number
descVersion description
robotCI robot number (1-30)
threadsCompilation thread count

Preview Parameters

ParameterDescription
qrcodeFormatQR code format: image / base64 / terminal, default image
qrcodeOutputDestQR code save path, default ./qrcode.jpg
pagePathPreview page path
searchQueryPreview page launch parameters
sceneScene value, default 1011

Compile Settings

ParameterDescription
es6ES6 to ES5
es7Enhanced compilation
minifyMinify all code
minifyJSMinify JS
minifyWXMLMinify WXML
minifyWXSSMinify WXSS
codeProtectCode protection
autoPrefixWXSSAuto-prefix WXSS

NPM Build Parameters

ParameterDescription
packNpmIgnoresPackage names to exclude during npm build, comma-separated
packageJsonPathRequired for packNpmManually, path to package.json
miniprogramNpmDistDirRequired for packNpmManually, build output directory

Other Parameters

ParameterDescription
uploadResultOutputDestUpload result save path
sourceMapSavePathSourceMap save path (required for getDevSourceMap)

Usage on Cloud Native Build

main:
  push:
    - stages:
        - name: miniprogram-ci
          image: tencentcom/miniprogram-ci
          settings:
            # Action to perform
            mode: upload
            # MiniProgram AppID
            appid: wxsomeappid
            # MiniProgram source directory (directory containing project.config.json)
            projectPath: ./
            # Private key file path
            privateKeyPath: ./private.wxsomeappid.key
            # Version number
            version: v1.0.0
            # Version description
            desc: CI auto upload
            # ES6 to ES5
            es6: true
            # Minify code
            minify: true

Build NPM then Upload

main:
  push:
    - stages:
        - name: miniprogram-ci
          image: tencentcom/miniprogram-ci
          settings:
            # Action to perform: build NPM first, then upload
            mode: packNpm,upload
            # MiniProgram AppID
            appid: wxsomeappid
            # MiniProgram source directory (directory containing project.config.json)
            projectPath: ./
            # Private key file path
            privateKeyPath: ./private.wxsomeappid.key
            # Version number
            version: v1.0.0

Preview Mode

main:
  push:
    - stages:
        - name: miniprogram-ci
          image: tencentcom/miniprogram-ci
          settings:
            # Action to perform: preview
            mode: preview
            # MiniProgram AppID
            appid: wxsomeappid
            # MiniProgram source directory (directory containing project.config.json)
            projectPath: ./
            # Private key file path
            privateKeyPath: ./private.wxsomeappid.key
            # QR code save path
            qrcodeOutputDest: ./preview-qrcode.jpg

Usage on GitHub Actions

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:
          # Action to perform
          PLUGIN_MODE: upload
          # MiniProgram AppID
          PLUGIN_APPID: wxsomeappid
          # MiniProgram source directory (directory containing project.config.json)
          PLUGIN_PROJECTPATH: ./
          # Private key content
          PLUGIN_PRIVATEKEY: ${{ secrets.MINIPROGRAM_PRIVATE_KEY }}
          # Version number
          PLUGIN_VERSION: v1.0.0
          # Version description
          PLUGIN_DESC: CI auto upload
          # ES6 to ES5
          PLUGIN_ES6: true
          # Minify code
          PLUGIN_MINIFY: true

Using Private Key File

- name: Upload MiniProgram
  uses: docker://tencentcom/miniprogram-ci:latest
  env:
    # MiniProgram AppID
    PLUGIN_APPID: wxsomeappid
    # MiniProgram source directory (directory containing project.config.json)
    PLUGIN_PROJECTPATH: ./
    # Private key file path
    PLUGIN_PRIVATEKEYPATH: ./private.wxsomeappid.key
    # Version number
    PLUGIN_VERSION: v1.0.0

Certificate Acquisition

  1. Log in to WeChat Public Platform
  2. Go to Development → Development Management → Development Settings → MiniProgram Code Upload
  3. Download the code upload key
  4. If you encounter IP whitelist issues, you can disable the whitelist restriction

More Information

About

miniprogram-ci

1.95 MiB
6 forks3 stars3 branches2 TagREADMEMIT license
Language
JavaScript93.4%
Shell4.7%
Dockerfile1.9%