用于小程序自动化上传、预览的命令行工具。
- 更改 PP、PR 配置
- 编译 Less、Typescript
- 上传代码到微信小程序平台。
npm install miniprogram-ci-tools -D
确保接入项目是标准的小程序项目
# 在项目根目录下执行
dkt-upload upload --ver 1.0.0 --desc "这是一个新的版本"
-
upload
: 上传指令 -
--ver
: (必填) 本次上传的版本号,如1.0.0
-
--desc
: (可选) 本次上传的版本描述 -
--path
: (可选) 小程序项目路径,默认为当前目录
本工具会读取项目根目录下的 ci.config.js
文件来获取小程序相关的配置。
ci.config.js
示例如下所示:
module.exports = {
miniprogramRoot: './',
// 环境: 定义小程序相关环境配置
environments: {
PP: {
appid: 'wx1234567890abcd',
env: 'PP',
privateKeyPath: 'xxx',
},
PR: {
appid: 'wx0987654321abcd',
env: 'PR',
privateKeyPath: 'xxx',
},
},
// 更新:定义需要修改哪些文件(主要是更改项目里的 appid 和切换 pp、pr 环境的配置)
update: {
files: [
{
path: 'project.config.json',
type: 'json',
key: 'appid',
value: '{{appid}}', // {{appid}} 会被替换为上面 environments 中对应环境的 appid
},
{
path: 'config/evnConfig.js',
type: 'regex',
// 这个正则表达式会找到 `EVN: '...'` 并替换引号内的内容
pattern: "(EVN:\\s*['\"])([^'\"]+)(['\"])",
value: '{{env}}', // {{env}} 会被替换为对应环境的 env 名称
},
],
},
// 编译:定义需要编译哪些文件(主要是 less 和 ts)
compile: {
cleanup: true, // 编译后删除源文件
rules: [
{
type: 'less',
glob: '**/*.less', // 匹配所有 .less 文件
},
{
type: 'ts',
glob: '**/*.ts',
},
],
},
// 上传
upload: {
ignores: ['node_modules/**/*'],
// miniprogram-ci 的上传设置(可在此进行覆盖)
setting: {
// minify: true,
// minifyWXML: true,
// minifyWXSS: true,
}
},
};
- IP 地址已被添加到小程序的 IP 白名单中或者关闭了白名单限制。
- 已从开发者后台下载了上传小程序的私钥。