uniapp 微信小程序代码自动上传到微信后台
1.微信后台获取上传密钥和白名单配置
- 生成小程序代码上传密钥
- IP 白名单配置(公网白名单)

生成完成之后下载到根目录或项目其他地方(一会用得到)
上传失败后,编译器会提示对应 ip
1 2
| 上传项目到微信平台失败 Error: {"errCode":-10008,"errMsg":"invalid ip: 220.165.xxx.xx, reference: https://developers.weixin.qq.com/miniprogram/dev/devtools/ci.html"}
|
2.脚本安装(npm、cnpm、yarn)
3.创建配置文件
在项目根目录创建 autoUpload.js
和添上面生成的密钥

autoUpload.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| const path = require("path"); import config from "./utils/config";
const ci = require("miniprogram-ci"); (async () => { const project = new ci.Project({ appid: config.appid, type: "miniProgram", projectPath: path.resolve(__dirname, "./unpackage/dist/build/mp-weixin"), privateKeyPath: path.resolve(__dirname, "./private.wx143e******c97bf0.key"), ignores: ["node_modules/**/*"], }); const uploadResult = await ci .upload({ project, version: "1.0.2", desc: "gk", setting: { es6: true, minifyJS: true, minifyWXML: true, minifyWXSS: true, minify: true, autoPrefixWXSS: true, }, usingComponents: true, lazyCodeLoading: "requiredComponents", onProgressUpdate: console.log, }) .then((res) => { console.log("成功", res); }) .catch((error) => { console.log("失败", error); throw error; }); })();
|
4.运行结果
上传代码

上传成功

官网地址