Developing Third-Party Custom Components

View Markdown

Last edited on 2026-08-10

Since Base Library version 2.2.1, Mini Program supports installing third-party packages via npm. Consequently, developing and using third-party custom component packages is also supported. For details on the npm feature, please refer to the related documentation first.

Preparation

To develop an open-source custom component package for others to use, you must first clarify how they intend to utilize this package. If users merely copy the Mini Program directory for direct use, they may skip this document. The remainder of this document describes the process under the premise of managing custom component packages with npm.

Before development, developers are required to have basic knowledge of node.js and npm. Additionally, developer tools with npm support must be prepared. Click here to download.

Download the Template

To help developers quickly set up a custom component package project suitable for development, debugging, and testing, WeChat officially provides a project template. There are three ways to download and use the template:

  • Directly download the zip file from GitHub and extract it.
  • Clone the repository from GitHub directly.
  • Initialize the project using the official command-line tool, which will be introduced below.

The build process in the project template is based on gulp + webpack. It supports commands for development, building, testing, etc. For details, please refer to the README.md file of the project template.

Command-Line Tool

The official command-line tool is provided to quickly initialize a project. Run the following command to install the command-line tool:

npm install -g @wechat-miniprogram/miniprogram-cli

Then, create a new empty directory as the project root directory, and execute the following command in this root directory:

miniprogram init --type custom-component

After the command execution is completed, you will find that many files have been generated in the project root directory. This is a complete project generated based on the official project template, upon which you can directly proceed with development and modifications.

For more usage details of the command-line tool, please refer to the README.md file in the GitHub repository.

Note: The first time you use miniprogram init to initialize a project, it will fetch the template from GitHub. Therefore, ensure that your network connection is stable.

Testing Tools

For unit testing custom components, please refer to the documentation Unit Testing.

Custom Component Examples

The following are custom components provided by the official. They can be referenced and used:

Custom Component Extension Examples

The following custom component extensions are provided by the official team and can be referenced and used: