universal-api
                                
                                
                                
                                    universal-api copied to clipboard
                            
                            
                            
                        Universal apis for web and miniapps.
Uni API 是一套支持小程序和 Web 容器的跨端 API 解决方案。
🎉 多容器支持 目前支持 Web、微信小程序、头条小程序、阿里小程序、百度小程序、快手小程序
🐂 API 丰富 覆盖 90+ API 实现
😯 文档完善 提供双语文档、丰富样例
0️⃣ 无框架依赖 无框架依赖,纯原生实现,可以兼容任意框架
🚀 极致体积 支持按需加载,按环境剔除无用代码
👍🏻 简易使用,快速接入 提供完善的 TypeScript 声明,让你可以摆脱文档,沉浸编程
快速使用
以 @uni/toast 为例
$ npm install @uni/toast
import { showToast } from '@uni/toast';
// string
showToast('Hi');
// object
showToast({
  content: 'hello',
  type: 'success',
  duration: 1000,
  success: () => {
    console.log('toast')
  }
});
// promise
showToast({
  content: 'hello',
  type: 'success',
  duration: 1000,
}).then(() => {});
文档
官方站点:https://universal-api.js.org/
示例
| 微信小程序 | 支付宝小程序 | 
|---|---|
![]()  | 
![]()  | 
贡献代码
请首先阅读 Rax 贡献代码指南,了解基础的规范。
起步
$ git clone [email protected]:raxjs/universal-api.git
$ yarn
$ yarn build
调试 API
$ yarn demo:init
$ yarn demo:dev
然后使用小程序 IDE 即可开始调试:
更新版本
API package 版本统一维护在根目录下的api-config.js,以 @uni/toast 为例:
module.exports = {
  toast: {
    path: 'src/packages/interactive/toast/src/index.ts',
    pkgInfo: [
      {
        version: '1.0.5',
        name: '@uni/toast',
      },
    ],
  },
}
| 参数 | 含义 | 默认值 | 
|---|---|---|
| path | 在源文件的路径 | - | 
| pkgInfo | npm包的属性(同packagejson写法) | - | 
| needCommonUtil | 是否需要公共utils | true | 
| unNeedSplit | 是否需要安环境分包 | false | 
大包版本需要更新根目录下的 package.json 的 version
  
