微信开发者工具
下载地址:稳定版 Stable Build (1.05.2103200)
Laya开发工具
2D项目使用 laya1.0版本就可以:LayaAir IDE 1.8.12
3D项目或者物理引擎项目,最好使用laya2.0:LayaAir IDE 2.11.0
1.资源控制
开发游戏时,可在laya开发,由于微信小游戏上传有资源4M限制,所以部分资源需要上传到自己资源服务器,通过外部加载实现。
可以将外部加载资源放在根目录下,本地开发时使用res目录,发布到微信开发者工具时,切换到自己资源服务器。
2.发布游戏
发布时,选择微信小游戏
发布前bin目录
注意在bin目录下放一个 game.js文件,文件内容如下:
require("weapp-adapter.js");
require("./code.js");
发布后wxgame目录
game.js:微信开发者工具启动游戏时,会从此加载。
game.json:小游戏配置,横竖屏,开域目录,小游戏跳转目录列表
{
"deviceOrientation": "portrait",
"showStatusBar": false,
"openDataContext": "src/myOpenDataContext",
"networkTimeout": {
"request": 10000,
"connectSocket": 10000,
"uploadFile": 10000,
"downloadFile": 10000
},
"permission":{
"scope.userLocation":{
"desc":"您的位置信息,将用于获取当前城市的打卡地点"
}
"navigateToMiniProgramAppIdList": [
"APPID","最多10个列表"
]
}
project.config.json:小游戏项目配置文件,在开发者工具里边修改,会保存在此目录。官方文档
Laya每次发布时,都会删除wxgame,因此配置文件修改后,要复制到bin目录下,否者下次发布时就没有了。
{
"description": "项目配置文件。",
"setting": {
"urlCheck": false,
"es6": false,
"postcss": true,
"minified": false,
"newFeature": true,
"ignoreUploadUnusedFiles": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
}
},
"compileType": "game",
"libVersion": "game",
"appid": "wxxxxxxxxxx",
"projectname": "xxxx",
"condition": {},
"packOptions": {
"ignore": [
{
"value": "res",
"type": "folder"
}
],
"include": []
},
}
微信小游戏图片尺寸
图片尺寸:安卓限制较小,ios超过2048像素,显示不出来
微信小游戏API
微信小游戏开发文档:文档地址
微信公众平台开发文档:文档地址
使用jenkins打包
1.工作空间:
设置为 release/wxgame
如果是正式提审服,需加个版本号。开发版本号,固定设置1.0.0即可。
2.执行bat:
@echo off
cd ..
cd ..
::更新代码 如果本地不发布,可忽略丢弃修改,每次发布时间都不一样
git checkout -- .laya\wxgame.json
git pull origin dev
::发布
layaair2-cmd publish -c wxgame
由于每次layaair2执行完后,都会关闭bat,后续无法执行,需再写一个bat。
::项目目录
set root=D:\Workspace\LayaProjects\Test_MiniGame
set release=%root%\release\wxgame
cd ..
svn revert wxgame/project.config.json
::删除多余 使用版本更新,每次发布后,新文件都会生成新的md5名字,旧的md5文件需要删除,svn不会将删除文件列入提交队列,需手动加入
svn st | findstr "^!" | for /f "tokens=2 delims= " %%G in ('findstr /r "^!"') do svn delete --force "%%G"
::添加
svn add wxgame --force --trust-server-cert
::上传SVN 可在本地拉取,使用微信开发者工具,进行调试
svn ci -m "auto commit" --no-unlock --trust-server-cert
::上传代码
node upload/upload.js %version%
3.upload.js
//版本号
let arguments = process.argv.splice(2);
//开发版本,固定1.0.0就可以
const version = arguments[0];
console.log("当前版本号:",version);
const ci = require('miniprogram-ci')
;(async () => {
const project = new ci.Project({
appid: 'wx34b15581429d709e',
type: 'miniGame',
projectPath: 'D:/Workspace/LayaProjects/Test-MiniGame/release/wxgame',
privateKeyPath: 'D:/Workspace/LayaProjects/Test-MiniGame/release/upload/upload.key',
ignores: ['node_modules/**/*'],
})
//上传
const uploadResult = await ci.upload({
project,
version,
desc: '正式版 自动上传',
setting: {
es6: false,
},
robot:2,
onProgressUpdate: console.log,
})
console.log(uploadResult)
})()
4.上传资源到服务器
飞书通知:feishu.sh
function sendMsg() {
current_time=$(date +"%Y-%m-%d %H:%M:%S")
msg_content="$1 $current_time"
payload='{"msg_type":"text","content":{"text":"'${msg_content}'"}}'
curl -X POST -H "Content-Type: application/json" -d "$payload" https://open.feishu.cn/open-apis/bot/v2/hook/飞书机器人编号
}
sendMsg $1