Mobile Development 7 min read

Using WeCOS to Reduce WeChat Mini Program Package Size

WeCOS is a command‑line tool that uploads a Mini Program’s local image assets to Tencent Cloud Object Storage, replaces the code’s image paths with COS URLs, removes the original files, and thus shrinks the package below the 1 MB upload limit, simplifying the otherwise manual process.

Tencent Cloud Developer
Tencent Cloud Developer
Tencent Cloud Developer
Using WeCOS to Reduce WeChat Mini Program Package Size

After publishing a WeChat Mini Program, many developers quickly start using the Mini Program development tools. The official documentation requires the compiled package size to be less than 1 MB; otherwise the upload fails.

Because Mini Programs often contain many local image resources, the package size can easily exceed the limit. The common workaround is to upload images to an external image hosting service and replace local references, but the built‑in tools do not support batch replacement.

To solve this problem, Tencent Cloud provides the WeCOS solution, a command‑line tool (also available as an npm package) that automatically uploads local image assets to Tencent Cloud Object Storage (COS), replaces the image URLs in the code, and removes the local image files, thereby shrinking the package.

Why We need WeCOS?

To improve Mini Program experience, the compiled code package must be smaller than 1 MB; packages larger than 1 MB will fail to upload.

The tool helps developers avoid the manual, error‑prone process of moving images to a CDN and updating references.

What is WeCOS?

WeCOS is a local CLI tool (also distributed via npm) that:

Uploads image resources in a Mini Program project to a configured COS bucket.

Replaces local image paths with the generated COS URLs.

Deletes the original local images and optionally backs them up.

Getting Started

Assume a Mini Program project directory app of about 10 MB with many images. The following three steps show how to use WeCOS.

Step 1 – Preparation

Register a Tencent Cloud account, enable COS, and create a bucket.

Install Node.js on the local machine.

Step 2 – Install WeCOS and configure

Install the tool globally:

npm install wecos -g

Create a wecos.config.json file in the same directory as the project with the essential fields:

{
  "appDir": "app",
  "appid": "
",
  "bucketname": "weixintest",
  "folder": "/wxtest",
  "region": "tj",
  "secret_id": "
",
  "secret_key": "
"
}

The configuration specifies the project directory, the COS bucket, optional sub‑folder, region (e.g., Tianjin "tj"), and the credentials needed for uploading.

Step 3 – Run the tool

Execute the command in the terminal:

wecos

The CLI uploads each image to COS, replaces the references in the source code, deletes the local files, and creates a wecos_backup folder containing the original images. After processing, the project size drops to a few kilobytes, and the Mini Program can be uploaded successfully without hitting the 1 MB limit.

WeCOS also offers advanced options such as custom domain replacement, file‑type filtering, and image compression.

Node.jsPackage OptimizationWeChat Mini ProgramTencent Cloud COSWeCOS
Tencent Cloud Developer
Written by

Tencent Cloud Developer

Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.