egret之分包加载学习笔记
将 scripts/wxgame/subpackage.ts 拷贝进您的项目https://github.com/himuil/subPackageDemo 下载链接
修改 config.wxgame.ts,将 ManifestPlugin 替换为 SubPackagePlugin (注意,您需要修改 build 和 publish)
1.引入文件
2.build处修改
3.publish处修改
修改 config.wxgame.ts 中的 CleanPlugin,将 subpackage 对应的目录清除
1.build和publish处都做修改
将示例项目的 EgretSubpackageLoading.js 拷贝进您的微信小游戏项目
修改微信小游戏项目的 game.json,参考示例项目,引入 subpackages 属性
修改微信小游戏项目的 game.js,参考示例项目,重点是添加调用 wx.loadSubPackage 的逻辑
require('./weapp-adapter.js');
require('./platform.js');
require('./manifest.js');
require('./egret.wxgame.js');
let runOptions = {
//以下为自动修改,请勿修改
//The following is automatically modified, please do not modify
//----auto option start----
entryClassName: "Main",
orientation: "auto",
frameRate: 30,
scaleMode: "fixedWidth",
contentWidth: 640,
contentHeight: 1136,
showFPS: false,
fpsStyles: "x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9",
showLog: false,
maxTouches: 2,
//----auto option end----
audioType: 0,
calculateCanvasScaleFactor: function (context) {
var backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1;
return (window.devicePixelRatio || 1) / backingStore;
}
};
const runEgret = function () {
egret.runEgret(runOptions);
}
if (wx.loadSubpackage) {
require("./EgretSubPackageLoading.js");
runOptions.entryClassName = "EgretSubPackageLoading";
runEgret();
let task = wx.loadSubpackage({
// 开发者根据自身需求更改
name: "stage1",
success: function () {
EgretSubPackageLoading.instance.onSuccess();
}
});
task.onProgressUpdate(res => {
EgretSubPackageLoading.instance.setProgress(res);
})
}
else {
//
require("./stage1/game.js");
runEgret();
}
---------------------
作者:snxxxx
来源:CSDN
原文:https://blog.csdn.net/snxxxx/article/details/81509184
页:
[1]