@lytjs/hmr 6.5.0 → 6.6.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 +79 -79
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
# @lytjs/hmr
|
|
2
|
-
|
|
3
|
-
LytJS 热模块替换(Hot Module Replacement)支持。
|
|
4
|
-
|
|
5
|
-
## 安装
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pnpm add -D @lytjs/hmr
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## 快速开始
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
import { createHMRClient, getHMRClient, accept } from '@lytjs/hmr';
|
|
15
|
-
|
|
16
|
-
// 创建 HMR 客户端
|
|
17
|
-
const client = createHMRClient({
|
|
18
|
-
url: 'ws://localhost:5173',
|
|
19
|
-
autoConnect: true,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
// 或者使用全局单例
|
|
23
|
-
const globalClient = getHMRClient();
|
|
24
|
-
|
|
25
|
-
// 接受模块更新
|
|
26
|
-
accept('/path/to/module.ts', (update) => {
|
|
27
|
-
console.log('模块已更新:', update);
|
|
28
|
-
});
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## 特性
|
|
32
|
-
|
|
33
|
-
- WebSocket 连接管理
|
|
34
|
-
- 模块更新处理
|
|
35
|
-
- 自动重连
|
|
36
|
-
- 状态保持
|
|
37
|
-
|
|
38
|
-
## API
|
|
39
|
-
|
|
40
|
-
### createHMRClient(options)
|
|
41
|
-
|
|
42
|
-
创建 HMR 客户端实例。
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
import { createHMRClient } from '@lytjs/hmr';
|
|
46
|
-
|
|
47
|
-
const client = createHMRClient({
|
|
48
|
-
url: 'ws://localhost:5173',
|
|
49
|
-
autoConnect: true,
|
|
50
|
-
});
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### getHMRClient(options)
|
|
54
|
-
|
|
55
|
-
获取全局 HMR 客户端单例。
|
|
56
|
-
|
|
57
|
-
### accept(path, handler)
|
|
58
|
-
|
|
59
|
-
注册模块更新处理函数。
|
|
60
|
-
|
|
61
|
-
### dispose(path, handler)
|
|
62
|
-
|
|
63
|
-
注册模块清理函数。
|
|
64
|
-
|
|
65
|
-
### client.connect()
|
|
66
|
-
|
|
67
|
-
连接到 HMR 服务器。
|
|
68
|
-
|
|
69
|
-
### client.disconnect()
|
|
70
|
-
|
|
71
|
-
断开连接。
|
|
72
|
-
|
|
73
|
-
### client.send(message)
|
|
74
|
-
|
|
75
|
-
发送消息。
|
|
76
|
-
|
|
77
|
-
## 许可证
|
|
78
|
-
|
|
79
|
-
MIT
|
|
1
|
+
# @lytjs/hmr
|
|
2
|
+
|
|
3
|
+
LytJS 热模块替换(Hot Module Replacement)支持。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @lytjs/hmr
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 快速开始
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { createHMRClient, getHMRClient, accept } from '@lytjs/hmr';
|
|
15
|
+
|
|
16
|
+
// 创建 HMR 客户端
|
|
17
|
+
const client = createHMRClient({
|
|
18
|
+
url: 'ws://localhost:5173',
|
|
19
|
+
autoConnect: true,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// 或者使用全局单例
|
|
23
|
+
const globalClient = getHMRClient();
|
|
24
|
+
|
|
25
|
+
// 接受模块更新
|
|
26
|
+
accept('/path/to/module.ts', (update) => {
|
|
27
|
+
console.log('模块已更新:', update);
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 特性
|
|
32
|
+
|
|
33
|
+
- WebSocket 连接管理
|
|
34
|
+
- 模块更新处理
|
|
35
|
+
- 自动重连
|
|
36
|
+
- 状态保持
|
|
37
|
+
|
|
38
|
+
## API
|
|
39
|
+
|
|
40
|
+
### createHMRClient(options)
|
|
41
|
+
|
|
42
|
+
创建 HMR 客户端实例。
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { createHMRClient } from '@lytjs/hmr';
|
|
46
|
+
|
|
47
|
+
const client = createHMRClient({
|
|
48
|
+
url: 'ws://localhost:5173',
|
|
49
|
+
autoConnect: true,
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### getHMRClient(options)
|
|
54
|
+
|
|
55
|
+
获取全局 HMR 客户端单例。
|
|
56
|
+
|
|
57
|
+
### accept(path, handler)
|
|
58
|
+
|
|
59
|
+
注册模块更新处理函数。
|
|
60
|
+
|
|
61
|
+
### dispose(path, handler)
|
|
62
|
+
|
|
63
|
+
注册模块清理函数。
|
|
64
|
+
|
|
65
|
+
### client.connect()
|
|
66
|
+
|
|
67
|
+
连接到 HMR 服务器。
|
|
68
|
+
|
|
69
|
+
### client.disconnect()
|
|
70
|
+
|
|
71
|
+
断开连接。
|
|
72
|
+
|
|
73
|
+
### client.send(message)
|
|
74
|
+
|
|
75
|
+
发送消息。
|
|
76
|
+
|
|
77
|
+
## 许可证
|
|
78
|
+
|
|
79
|
+
MIT
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED