Egret问题总结
1.使用EUI的项目发布到微信小游戏自定义皮肤组件找不到
在所有EUI皮肤类底部追加:
window[“类名”] = 类名;
比如Alert皮肤类 window[“Alert”] = Alert;
2.加载图片跨域限制
设置图片匿名访问
egret.ImageLoader.crossOrigin = “anonymous”;
3.如何压缩类库
打开 /scripts/config.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
else if (command == 'publish') { const outputDir = `bin-release/web/${version}`; return { outputDir, commands: [ new CustomPlugin(), new CompilePlugin({ libraryType: "release", defines: { DEBUG: false, RELEASE: true } }), new ExmlPlugin('commonjs'), // 非 EUI 项目关闭此设置 new UglifyPlugin([ { sources: ["main.js"], target: "main.min.js" } ]), new RenamePlugin({ verbose: true, hash: 'crc32', matchers: [ { from: "**/*.js", to: "[path][name]_[hash].[ext]" } ] }), new ManifestPlugin({ output: "manifest.json" }) ] } } |
修改 UglifyPlugin 插件信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
new UglifyPlugin([ { // 需要被压缩的文件 sources: [ "libs/modules/egret/egret.min.js", "libs/modules/egret/egret.web.min.js", "libs/modules/assetsmanager/assetsmanager.min.js", "libs/modules/tween/tween.min.js", "libs/modules/game/game.min.js", "libs/modules/promise/promise.min.js" ], // 压缩后的文件 target: "lib.min.js" }, { sources: ["main.js"], target: "main.min.js" } ]) |
如果使用了EUI 后面再加上
1 2 3 4 |
{ sources: ["resource/default.thm.js"], target: "default.thm.min.js" } |
4.手机震动功能
1 2 3 4 5 6 7 8 |
public static vibrate():void { if (navigator.vibrate) { navigator.vibrate(300); } else if (navigator["webkitVibrate"]) { navigator["webkitVibrate"](300); } } |