@foldkit/vite-plugin 0.1.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 +49 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# @foldkit/vite-plugin
|
|
2
|
+
|
|
3
|
+
Vite plugin for Foldkit that enables hot module reloading with model preservation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D @foldkit/vite-plugin
|
|
9
|
+
# or
|
|
10
|
+
pnpm add -D @foldkit/vite-plugin
|
|
11
|
+
# or
|
|
12
|
+
yarn add -D @foldkit/vite-plugin
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Add the plugin to your `vite.config.ts`:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { foldkit } from '@foldkit/vite-plugin'
|
|
21
|
+
import { defineConfig } from 'vite'
|
|
22
|
+
|
|
23
|
+
export default defineConfig({
|
|
24
|
+
plugins: [foldkit()],
|
|
25
|
+
})
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## What it does
|
|
29
|
+
|
|
30
|
+
When you save a file during development, the plugin:
|
|
31
|
+
|
|
32
|
+
1. Preserves your application's current state (model)
|
|
33
|
+
2. Triggers a full page reload
|
|
34
|
+
3. Restores the preserved model after reload
|
|
35
|
+
|
|
36
|
+
This means you can make code changes without losing your application's state - forms stay filled, counters keep their values, game positions are maintained, etc.
|
|
37
|
+
|
|
38
|
+
## How it works
|
|
39
|
+
|
|
40
|
+
The plugin uses Vite's WebSocket connection to communicate between the dev server and browser:
|
|
41
|
+
|
|
42
|
+
- **On file change**: The browser sends the current model to the Vite server for preservation
|
|
43
|
+
- **On reload**: The browser requests the preserved model from the server and initializes the Foldkit runtime with it
|
|
44
|
+
|
|
45
|
+
Model is preserved across hot reloads but cleared on manual browser refreshes, giving you control over when to reset your app.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAA;AAKjD,eAAO,MAAM,OAAO,QAAO,MAO1B,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
let preservedModel = undefined;
|
|
2
|
+
let isHmrReload = false;
|
|
3
|
+
export const foldkit = () => {
|
|
4
|
+
return {
|
|
5
|
+
name: 'foldkit-hmr',
|
|
6
|
+
apply: 'serve',
|
|
7
|
+
configureServer,
|
|
8
|
+
handleHotUpdate,
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
const configureServer = (server) => {
|
|
12
|
+
server.ws.on('foldkit:preserve-model', (model) => {
|
|
13
|
+
preservedModel = model;
|
|
14
|
+
});
|
|
15
|
+
server.ws.on('foldkit:request-model', () => {
|
|
16
|
+
server.ws.send('foldkit:restore-model', isHmrReload ? preservedModel : undefined);
|
|
17
|
+
if (!isHmrReload) {
|
|
18
|
+
preservedModel = undefined;
|
|
19
|
+
}
|
|
20
|
+
isHmrReload = false;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const handleHotUpdate = ({ server }) => {
|
|
24
|
+
isHmrReload = true;
|
|
25
|
+
server.ws.send({ type: 'full-reload' });
|
|
26
|
+
return [];
|
|
27
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@foldkit/vite-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vite plugin for Foldkit hot module reloading with state preservation",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"clean": "rimraf dist *.tsbuildinfo",
|
|
20
|
+
"build": "pnpm run clean && tsc -b",
|
|
21
|
+
"watch": "tsc -b --watch",
|
|
22
|
+
"typecheck": "tsc -b --noEmit"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"vite": "^6.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.4.0",
|
|
29
|
+
"vite": "^6.0.3"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"vite",
|
|
33
|
+
"vite-plugin",
|
|
34
|
+
"foldkit",
|
|
35
|
+
"hmr",
|
|
36
|
+
"hot-reload"
|
|
37
|
+
],
|
|
38
|
+
"author": "Devin Jameson",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/devinjameson/foldkit.git",
|
|
43
|
+
"directory": "packages/vite-plugin-foldkit"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=18.0.0"
|
|
50
|
+
}
|
|
51
|
+
}
|