0.2.0 • Published 6 years ago
@shed/platform v0.2.0
@shed/platform
:hammer: 以微信小游戏为基准,统一各小游戏平台提供的API,并 Promise 化
各个小游戏平台均实现了 IPlatform 接口
当使用 @shed/cli 编译到某个平台时,会利用 rollup 的 tree shaking 自动将其他无关平台的代码删掉。
安装
npm install @shed/platform或使用 yarn
yarn add @shed/platform用法
let api:IPlatform = Platform.get();
api.xxx();如果在微信平台,上边的代码经过 @shed/cli 编译后相当于
wx.xxx();环境判断
let platform = Platform.get();
if(platform.isWX){
console.log('是微信平台');
}
if(platform.isH5){
console.log('是Web平台');
}