vite-plugin-mirrorstate 0.1.0-alpha.0 → 0.2.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 +19 -0
- package/dist/index.js +10 -0
- package/package.json +6 -1
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# `vite-plugin-mirrorstate`
|
|
2
|
+
|
|
3
|
+
Vite plugin for bi-directional state synchronization with JSON files on disk.
|
|
4
|
+
|
|
5
|
+
**Note:** Both `vite-plugin-mirrorstate` and `react-mirrorstate` are required to use MirrorState.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install vite-plugin-mirrorstate react-mirrorstate
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Documentation
|
|
14
|
+
|
|
15
|
+
For full documentation, examples, and API reference, see the [main MirrorState repository](https://github.com/szymonkaliski/mirrorstate).
|
|
16
|
+
|
|
17
|
+
## License
|
|
18
|
+
|
|
19
|
+
MIT
|
package/dist/index.js
CHANGED
|
@@ -56,6 +56,11 @@ export function mirrorStatePlugin(options = {}) {
|
|
|
56
56
|
}));
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
|
+
// Invalidate the virtual module for HMR
|
|
60
|
+
const mod = server.moduleGraph.getModuleById("virtual:mirrorstate/initial-states");
|
|
61
|
+
if (mod) {
|
|
62
|
+
server.moduleGraph.invalidateModule(mod);
|
|
63
|
+
}
|
|
59
64
|
logger(`Mirror file changed externally: ${name}`);
|
|
60
65
|
}
|
|
61
66
|
catch (error) {
|
|
@@ -110,6 +115,11 @@ export function mirrorStatePlugin(options = {}) {
|
|
|
110
115
|
recentWrites.add(filePath);
|
|
111
116
|
// Write state to file
|
|
112
117
|
fs.writeFileSync(filePath, jsonContent);
|
|
118
|
+
// Invalidate the virtual module for HMR
|
|
119
|
+
const mod = server.moduleGraph.getModuleById("virtual:mirrorstate/initial-states");
|
|
120
|
+
if (mod) {
|
|
121
|
+
server.moduleGraph.invalidateModule(mod);
|
|
122
|
+
}
|
|
113
123
|
// Broadcast to other clients (exclude sender to prevent echo)
|
|
114
124
|
wss.clients.forEach((client) => {
|
|
115
125
|
if (client !== ws && client.readyState === client.OPEN) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-mirrorstate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Vite plugin for bidirectional state synchronization through *.mirror.json files",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
],
|
|
17
17
|
"author": "",
|
|
18
18
|
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/szymonkaliski/mirrorstate.git",
|
|
22
|
+
"directory": "packages/vite-plugin-mirrorstate"
|
|
23
|
+
},
|
|
19
24
|
"dependencies": {
|
|
20
25
|
"chokidar": "^3.5.3",
|
|
21
26
|
"debug": "^4.4.1",
|