Skip to main content

Mini Program Plugin

The Mini Program Plugin provides complete toolchain support for WeChat Mini Program development and deployment, including code upload, preview, build, and other functions.

Configuration

Environment Variables

# Set Mini Program Code Upload Key (choose one of two)
export MINIPROGRAM_PRIVATE_KEY="private key content"
# Or
export MINIPROGRAM_PRIVATE_KEY_PATH="/path/to/private.key"

# Enabling the Mini Program Plugin
export CLOUDBASE_MCP_PLUGINS_ENABLED="env,database,functions,hosting,storage,setup,interactive,rag,gateway,download,miniprogram"

MCP Configuration

{
"mcpServers": {
"cloudbase": {
"command": "npx",
"args": ["npm-global-exec@latest", "@cloudbase/cloudbase-mcp@latest"],
"env": {
"MINIPROGRAM_PRIVATE_KEY": "your Mini Program private key",
"CLOUDBASE_MCP_PLUGINS_ENABLED": "env,database,functions,hosting,storage,setup,interactive,rag,gateway,download,miniprogram"
}
}
}
}

Tools

uploadMiniprogramCode

Upload Mini Program code to the WeChat platform

Parameters:

  • appId: Mini Program appId
  • projectPath: Project path
  • version: Version number
  • desc: Version description (Optional)
  • setting: Compilation settings (Optional)
  • robot: Robot number 1-30 (Optional)
  • type: Project type miniProgram/miniGame (Optional)

previewMiniprogramCode

Preview Mini Program code and generate a QR code

Parameters:

  • appId: Mini Program appId
  • projectPath: Project path
  • desc: Preview description (Optional)
  • setting: Compilation settings (Optional)
  • robot: Robot number 1-30 (Optional)
  • type: Project type miniProgram/miniGame (Optional)
  • qrcodeFormat: QR code format image/base64/terminal (Optional)
  • qrcodeOutputDest: QR code output path (Optional)
  • pagePath: Preview page path (Optional)
  • searchQuery: Preview page parameters (Optional)

buildMiniprogramNpm

Build Mini Program npm package

Parameters:

  • appId: Mini Program appId
  • projectPath: Project path
  • type: Project type miniProgram/miniGame (Optional)
  • robot: Robot number 1-30 (Optional)

getMiniprogramProjectConfig

Getting Mini Program Project Configuration

Parameters:

  • appId: Mini Program appId
  • projectPath: Project path
  • type: Project type miniProgram/miniGame (Optional)

getMiniprogramSourceMap

Retrieve the SourceMap of the most recently uploaded version for production environment error debugging.

Parameters:

  • appId: Mini Program appId
  • projectPath: Project path
  • robot: Specify which ci robot to use, 1-30
  • sourceMapSavePath: SourceMap save path
  • type: Project type miniProgram/miniGame (Optional)

checkMiniprogramCodeQuality

Check the mini-program code quality and generate a quality report (requires miniprogram-ci 1.9.11+)

Parameters:

  • appId: Mini Program appId
  • projectPath: Project path
  • saveReportPath: Quality report save path
  • type: Project type miniProgram/miniGame (Optional)

packMiniprogramNpmManually

Mini Program npm build with customizable node_modules location, supporting complex project structures

Parameters:

  • packageJsonPath: The path to the package.json corresponding to the node_modules to be built
  • miniprogramNpmDistDir: The target location for the built miniprogram_npm
  • ignores: Specifies rules to exclude (optional)

Use Cases

Development Workflow

  1. Build Dependencies

    Call buildMiniprogramNpm to build the npm package.
    Call packMiniprogramNpmManually to custom-build complex project structures.
  2. Preview Testing

    Call previewMiniprogramCode to generate a preview QR code.
  3. Release and Deployment

    Call uploadMiniprogramCode to upload the code to the WeChat platform.
  4. Debugging and Optimization

    Call getMiniprogramSourceMap to retrieve the SourceMap for error debugging.
    Call checkMiniprogramCodeQuality to check the code quality and generate a report.

Secret Key Configuration

Before using this plugin, you need to configure it on the WeChat Official Account Platform:

  1. Visit WeChat Official Account Platform
  2. Go to "Management-Development Management-Development Settings-Mini Program Code Upload"
  3. Generate the "Code Upload Key"
  4. Configure IP allowlist (Recommended to enable)

Notes

  • The Code Upload Key has permissions to preview and upload code.
  • The key is not stored in plaintext on the WeChat Official Account Platform.
  • The key must be reset if lost; please store it securely.
  • It is recommended to enable the IP allowlist to reduce security risks.

Frequently Asked Questions

Q: How to obtain the Mini Program appId?

A: The appId can be viewed on the Mini Program management page in the WeChat Official Account Platform.

Q: What is the purpose of the robot ID?

A: The robot ID is used to distinguish between different upload tasks and can be set to a number 1-30.

Q: What compilation settings are supported?

A: Supports common compilation options such as ES6/ES7 transformation, code minification, and WXSS minification.

Q: What is the purpose of SourceMap?

A: SourceMap is used for debugging errors in the production environment. It maps errors in minified code back to the original source code locations, facilitating issue localization.

Q: What does the code quality check include?

A: Includes multi-dimensional quality analysis such as coding standards, performance issues, potential bugs, and optimization opportunities, generating a detailed quality report.

Q: When is it necessary to use a custom npm build?

A: It is used when the project has a special directory structure, requires customizing the location of node_modules, or has specific build requirements.