@fgz/wxmini-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -0
- package/dist/index.cjs +1813 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +887 -0
- package/dist/index.d.ts +887 -0
- package/dist/index.js +1767 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# wxmini-sdk
|
|
2
|
+
|
|
3
|
+
微信小程序桥接通信 SDK,通过 WebSocket CSON-RPC 协议与微信小程序原生端通信。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 🚀 **纯 TypeScript** — 无 Vue/React 等框架依赖
|
|
8
|
+
- 📦 **多格式输出** — 同时支持 ESM 和 CJS
|
|
9
|
+
- 🔌 **即插即用** — 包含完整的类型定义 (`.d.ts`)
|
|
10
|
+
- 🔄 **WebSocket RPC** — 基于 CSON 二进制协议的高效通信
|
|
11
|
+
|
|
12
|
+
## 安装
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install wxmini-sdk
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 快速开始
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { WxMini } from 'wxmini-sdk'
|
|
22
|
+
|
|
23
|
+
const wxMini = new WxMini()
|
|
24
|
+
|
|
25
|
+
// 配置
|
|
26
|
+
wxMini.serverUrl = 'https://your-server.com'
|
|
27
|
+
wxMini.appUuid = 'your-app-uuid'
|
|
28
|
+
wxMini.bridgeWebSocketUrl = 'wss://your-bridge-ws-url'
|
|
29
|
+
|
|
30
|
+
// 使用
|
|
31
|
+
const config = wxMini.queryConfig()
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 构建
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# 安装依赖
|
|
38
|
+
npm install
|
|
39
|
+
|
|
40
|
+
# 构建
|
|
41
|
+
npm run build
|
|
42
|
+
|
|
43
|
+
# 开发模式(监听变化)
|
|
44
|
+
npm run dev
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 输出
|
|
48
|
+
|
|
49
|
+
构建后将在 `dist/` 目录生成:
|
|
50
|
+
|
|
51
|
+
- `index.js` — ESM 模块
|
|
52
|
+
- `index.cjs` — CommonJS 模块
|
|
53
|
+
- `index.d.ts` — TypeScript 类型定义
|
|
54
|
+
|
|
55
|
+
## 项目结构
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
wxmini-sdk/
|
|
59
|
+
├── src/
|
|
60
|
+
│ ├── index.ts # 入口文件 & 公共API导出
|
|
61
|
+
│ ├── wx-mini.ts # WxMini 核心类
|
|
62
|
+
│ ├── ws-client.ts # WebSocket RPC 客户端
|
|
63
|
+
│ ├── cson.ts # CSON 编解码
|
|
64
|
+
│ ├── cson-core.ts # CSON 基础类型
|
|
65
|
+
│ ├── pojo.ts # WxMini 相关 POJO 类
|
|
66
|
+
│ ├── pojo-registry.ts # POJO 类型注册表
|
|
67
|
+
│ ├── rpc-core.ts # RPC 服务基类
|
|
68
|
+
│ ├── rpc-interface.ts # IWxMiniBridgeService
|
|
69
|
+
│ ├── device-info.ts # 设备/环境检测
|
|
70
|
+
│ └── utils.ts # 通用工具类
|
|
71
|
+
├── package.json
|
|
72
|
+
├── tsconfig.json
|
|
73
|
+
└── tsup.config.ts
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 从原 Vue 项目的变更说明
|
|
77
|
+
|
|
78
|
+
本 SDK 从 `jdv_wxmini` Vue 项目中抽取而来,主要变更:
|
|
79
|
+
|
|
80
|
+
1. **移除 Vue 依赖** — 所有 `@/` 路径别名替换为相对路径
|
|
81
|
+
2. **移除 GuiMgr 依赖** — `WsClient` 中的服务端回调处理改为可注入的 `ServerCallbackHandler` 接口
|
|
82
|
+
3. **精简 POJO** — 从 7000+ 行的 `all_pojo.ts` 中仅抽取 WxMini 所需的类
|
|
83
|
+
4. **环境检测改为函数** — `isWxMiniprogram` 等改为函数调用,支持 SSR 环境
|
|
84
|
+
5. **新增 close() 方法** — `WxMini` 类新增资源清理方法
|