@seedprotocol/vite 0.7.4-next.793.g6dd83dd → 0.7.5-next.850.g9ab585b

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.
Files changed (2) hide show
  1. package/README.md +93 -0
  2. package/package.json +17 -2
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # @seedprotocol/vite
2
+
3
+ [![npm](https://img.shields.io/npm/v/@seedprotocol/vite.svg)](https://www.npmjs.com/package/@seedprotocol/vite)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Docs](https://img.shields.io/badge/docs-seedprotocol.io-0B6E4F)](https://seedprotocol.io)
6
+
7
+ Vite plugin for browser and Electron-renderer apps that use [`@seedprotocol/sdk`](https://www.npmjs.com/package/@seedprotocol/sdk). It sets up Node polyfills, ZenFS `fs` aliases, CommonJS/ESM interop fixes, dependency pre-bundling, and the cross-origin isolation headers that SQLite WASM and OPFS need. Your app can then import the SDK without its own workarounds.
8
+
9
+ ## Installation
10
+
11
+ `vite` (8 or later) is a peer dependency. `vite-plugin-node-polyfills` is a dependency of this package, so you do not need to install it.
12
+
13
+ ```bash
14
+ npm install -D @seedprotocol/vite
15
+ # or
16
+ bun add -d @seedprotocol/vite
17
+ # or
18
+ pnpm add -D @seedprotocol/vite
19
+ ```
20
+
21
+ Your app also needs `@seedprotocol/sdk` and the ZenFS packages it uses in the browser. Pin the versions the SDK declares (currently `@zenfs/core@2.5.6` and `@zenfs/dom@1.2.9`) so only one copy is installed.
22
+
23
+ ## Usage
24
+
25
+ `seedVitePlugin()` returns an **array** of plugins, so spread it into `plugins`:
26
+
27
+ ```ts
28
+ // vite.config.ts
29
+ import { defineConfig } from 'vite'
30
+ import react from '@vitejs/plugin-react'
31
+ import { seedVitePlugin } from '@seedprotocol/vite'
32
+
33
+ export default defineConfig({
34
+ plugins: [react(), ...seedVitePlugin()],
35
+ })
36
+ ```
37
+
38
+ Initialize ZenFS in your app entry before you use the SDK (`autoInit` is off by default):
39
+
40
+ ```ts
41
+ import { configure } from '@zenfs/core'
42
+ import { IndexedDB } from '@zenfs/dom'
43
+
44
+ await configure({ mounts: { '/': IndexedDB } })
45
+ ```
46
+
47
+ After you add or upgrade the plugin, delete `node_modules/.vite` and restart the dev server.
48
+
49
+ ## What it configures
50
+
51
+ - **Node polyfills** for `path`, `buffer`, `events`, `string_decoder` and `util`. Full `stream` and `crypto` polyfills are left out because they break Vite SSR and React Router prerender. A minimal `stream` stub is aliased instead.
52
+ - **Cross-origin isolation headers** on the dev and preview servers: `Cross-Origin-Opener-Policy: same-origin`, `Cross-Origin-Embedder-Policy: credentialless`, `Cross-Origin-Resource-Policy: same-origin`. They are applied on `writeHead` too, so React Router Framework Mode HTML responses get them.
53
+ - **`fs` aliases** to ZenFS (`fs`, `fs/promises`, `node:fs`, `node:fs/promises`), plus stable ESM entry points for `@zenfs/core` and `@zenfs/dom`.
54
+ - **Interop shims** for `debug` default imports and the `nanoid-dictionary` ESM build.
55
+ - **`optimizeDeps.include`** for fragile CommonJS dependencies, including the SDK's nested EAS SDK.
56
+ - **Inline `global` / `process` shims** in `index.html`. `process.env.NODE_ENV` follows the Vite `mode`, so React Refresh works under `vite serve`.
57
+
58
+ ## Options
59
+
60
+ ```ts
61
+ seedVitePlugin({
62
+ includeNodePolyfills: true,
63
+ isolationHeaders: true,
64
+ autoInit: false,
65
+ debug: false,
66
+ })
67
+ ```
68
+
69
+ | Option | Default | Description |
70
+ |--------|---------|-------------|
71
+ | `includeNodePolyfills` | `true` | Add `vite-plugin-node-polyfills` with the defaults above. Set `false` for React Router Framework Mode or SPA prerender. |
72
+ | `isolationHeaders` | `true` | COOP/COEP/CORP on dev and preview servers. `false` disables them; `{ coop, coep, corp }` overrides individual values. |
73
+ | `fsModules` | `['fs', 'fs/promises', 'node:fs', 'node:fs/promises']` | Modules aliased to ZenFS. |
74
+ | `autoInit` | `false` | Inject a ZenFS init script into `index.html`. Browsers cannot resolve its bare `@zenfs/*` imports without an import map, so prefer initializing ZenFS in your entry. |
75
+ | `debug` | `false` | Log plugin diagnostics. |
76
+
77
+ The options type is exported as `SeedVitePluginOptions`.
78
+
79
+ ## Production hosting
80
+
81
+ The headers only apply to `vite serve` and `vite preview`. In production, your host must send `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: credentialless` (or `require-corp`) on the HTML document, for example through nginx or a Netlify `_headers` file. Without them, SQLite WASM and OPFS storage do not work.
82
+
83
+ ## Documentation
84
+
85
+ - Full documentation: **https://seedprotocol.io**
86
+ - [Vite renderer guide and troubleshooting](https://github.com/JournoLabs/seed-protocol-sdk/blob/main/packages/vite/VITE_RENDERER.md)
87
+ - [Getting started](https://github.com/JournoLabs/seed-protocol-sdk/blob/main/docs/GETTING_STARTED.md)
88
+ - Core SDK: [`@seedprotocol/sdk`](https://www.npmjs.com/package/@seedprotocol/sdk)
89
+ - React bindings: [`@seedprotocol/react`](https://www.npmjs.com/package/@seedprotocol/react)
90
+
91
+ ## License
92
+
93
+ MIT
package/package.json CHANGED
@@ -1,9 +1,20 @@
1
1
  {
2
2
  "name": "@seedprotocol/vite",
3
- "version": "0.7.4-next.793.g6dd83dd",
4
- "description": "Vite plugin for Seed Protocol browser/renderer apps",
3
+ "version": "0.7.5-next.850.g9ab585b",
4
+ "description": "Vite plugin for browser apps using @seedprotocol/sdk: Node polyfills, ZenFS aliases, CJS interop fixes and cross-origin isolation headers",
5
+ "keywords": [
6
+ "seed-protocol",
7
+ "vite",
8
+ "vite-plugin",
9
+ "zenfs",
10
+ "opfs",
11
+ "sqlite-wasm",
12
+ "polyfills",
13
+ "cross-origin-isolation"
14
+ ],
5
15
  "type": "module",
6
16
  "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
7
18
  "exports": {
8
19
  ".": {
9
20
  "import": {
@@ -59,6 +70,10 @@
59
70
  "url": "git+https://github.com/JournoLabs/seed-protocol-sdk.git",
60
71
  "directory": "packages/vite"
61
72
  },
73
+ "homepage": "https://github.com/JournoLabs/seed-protocol-sdk/tree/main/packages/vite#readme",
74
+ "bugs": {
75
+ "url": "https://github.com/JournoLabs/seed-protocol-sdk/issues"
76
+ },
62
77
  "publishConfig": {
63
78
  "access": "public"
64
79
  }