新增一个文件夹conf,其中包含private.*.key文件与upload.js文件
private.*.key:小程序的上传密钥,在小程序后台获取,需要管理员权限
upload.js 上传js文件,使用此文件需要提前在后台配置上传IP,需要管理员权限
新增一个配置文件package-build.json,因为uniapp自带有package.json文件,所以新增-build后缀
mv conf ./unpackage/dist/build/mp-weixin //将conf移动到打包文件下 mv package-build.json ./unpackage/dist/build/mp-weixin/package.json //移动到打包文件并更正名称 cd ./unpackage/dist/build/mp-weixin //切换到指定目录 cnpm i //下载依赖 npm run upload //上传代码 !!!需要注意这里的服务器ip要在后台配置
upload.js:
const ci = require('miniprogram-ci') let { wxVersion: version, wxDesc: desc } = require('../package.json').wx if (!version) version = 'v1.0.0' if (!desc) desc = new Date() + '上传' const project = new ci.Project({ appid, type: 'miniProgram', projectPath: process.cwd(), privateKeyPath:`${process.cwd()}/conf/private.${appid}.key`, ignores: ['node_modules/**/*'], }) console.log({ appid, type: 'miniProgram', projectPath: process.cwd(), privateKeyPath:`${process.cwd()}/conf/private.${appid}.key`, ignores: ['node_modules/**/*'], }) ci.upload({ project, version, desc, setting: { minify: true, }, }).then(res => { console.log(res) console.log('上传成功') }).catch(error => { if (error.errCode == -1) { console.log('上传成功') } console.log(error) console.log('上传失败') process.exit(-1) })
阿里云微信小程序构建发布 https://help.aliyun.com/document_detail/202392.html?spm=a2c4g.201891.0.0.70cf7d77HXTjAA