@vrowzer/vite-plugin 0.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/LICENSE +20 -0
- package/README.md +290 -0
- package/dist/ide/assets/css.worker-uWEFNxvl.js +89 -0
- package/dist/ide/assets/html.worker-1tLoAl5Z.js +502 -0
- package/dist/ide/assets/json.worker-CL3sVQd6.js +58 -0
- package/dist/ide/assets/ts.worker-BFpNHPy5.js +67719 -0
- package/dist/ide/css-CPSW8DVZ.js +286 -0
- package/dist/ide/cssMode-B5DtFEwy.js +65 -0
- package/dist/ide/graphql-BteLL2CG.js +176 -0
- package/dist/ide/handlebars-BcqMM6pa.js +412 -0
- package/dist/ide/html-CxO5OaJl.js +333 -0
- package/dist/ide/htmlMode-DxpUG2jm.js +74 -0
- package/dist/ide/ide.css +2 -0
- package/dist/ide/ide.js +5523 -0
- package/dist/ide/javascript-CvtLx4_Z.js +21 -0
- package/dist/ide/jsonMode-LVtiYWKr.js +449 -0
- package/dist/ide/less-BubkcFWW.js +244 -0
- package/dist/ide/lspLanguageFeatures-BDyekQt2.js +1455 -0
- package/dist/ide/markdown-DPB5N4OB.js +264 -0
- package/dist/ide/mdx-Sun87_nd.js +329 -0
- package/dist/ide/monaco.contribution-DVj8eGe_.js +116 -0
- package/dist/ide/pug-BONHZNEg.js +302 -0
- package/dist/ide/scss-0r6NeK1P.js +419 -0
- package/dist/ide/shell-Vh_eZpea.js +225 -0
- package/dist/ide/toggleHighContrast-DI4ZeqFk.js +113328 -0
- package/dist/ide/tsMode-BKTkt1bt.js +567 -0
- package/dist/ide/typescript-CHC4VYBW.js +257 -0
- package/dist/ide/workers-IG_hD8Jy.js +47 -0
- package/dist/ide/xml-C0QFzMaz.js +130 -0
- package/dist/ide/yaml-o-RP7lYY.js +223 -0
- package/dist/index.d.mts +138 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1335 -0
- package/dist/index.mjs.map +1 -0
- package/dist/manifest-generate.d.mts +89 -0
- package/dist/manifest-generate.d.mts.map +1 -0
- package/dist/manifest-generate.mjs +438 -0
- package/dist/manifest-generate.mjs.map +1 -0
- package/package.json +88 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 kazuya kawaguchi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
# @vrowzer/vite-plugin
|
|
2
|
+
|
|
3
|
+
Vite plugin for [vrowzer](https://github.com/kazupon/vrowzer) - browser-based Vite dev server preview system.
|
|
4
|
+
|
|
5
|
+
This plugin configures Vite for running `@vrowzer/vite-dev-server` in Service Worker and Web Worker environments. It handles auto manifest generation, Node.js polyfills, CORS headers, `process` global injection, WASM file copying, Worker config extraction/prebundling, Service Worker bundling, and an experimental browser IDE.
|
|
6
|
+
|
|
7
|
+
## đŋ Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
# npm
|
|
11
|
+
npm install -D @vrowzer/vite-plugin
|
|
12
|
+
|
|
13
|
+
# pnpm
|
|
14
|
+
pnpm add -D @vrowzer/vite-plugin
|
|
15
|
+
|
|
16
|
+
# yarn
|
|
17
|
+
yarn add -D @vrowzer/vite-plugin
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## đ Usage
|
|
21
|
+
|
|
22
|
+
### Auto mode (default)
|
|
23
|
+
|
|
24
|
+
The plugin automatically generates a manifest from the project's `package.json` dependencies and source files. No manual manifest file or `VrowzerManifest()` plugin is needed.
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
// vite.config.ts
|
|
28
|
+
import vue from '@vitejs/plugin-vue'
|
|
29
|
+
import { Vrowzer } from '@vrowzer/vite-plugin'
|
|
30
|
+
import { defineConfig } from 'vite'
|
|
31
|
+
|
|
32
|
+
export default defineConfig({
|
|
33
|
+
plugins: [vue(), Vrowzer()]
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The auto-generated manifest is available via the `virtual:vrowzer-manifest` virtual module:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import manifest from 'virtual:vrowzer-manifest'
|
|
41
|
+
|
|
42
|
+
const vrowzer = Vrowzer({ basePath: '/__preview__/' })
|
|
43
|
+
await vrowzer.ready({
|
|
44
|
+
files: { ...manifest.files, ...manifest.nodeModules }
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
When the host page and preview content are in different directories, use `manifest.sourceDir`:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
Vrowzer({
|
|
52
|
+
manifest: {
|
|
53
|
+
sourceDir: './app', // scan ./app/ for preview content
|
|
54
|
+
targets: ['vue'] // only include vue (+ transitive deps)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Manual mode
|
|
60
|
+
|
|
61
|
+
For advanced use cases (e.g. multiple fixtures), disable auto mode and use `VrowzerManifest()` with a manually created `vrowzer-manifest.json`.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
// vite.config.ts
|
|
65
|
+
import { Vrowzer, VrowzerManifest } from '@vrowzer/vite-plugin'
|
|
66
|
+
import { defineConfig } from 'vite'
|
|
67
|
+
|
|
68
|
+
export default defineConfig({
|
|
69
|
+
plugins: [VrowzerManifest(), Vrowzer({ auto: false })]
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Browser IDE (experimental)
|
|
74
|
+
|
|
75
|
+
Enable the browser IDE to get a full development environment at `/__vrowzer__/` with File Explorer, Monaco Editor, and live Preview.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
Vrowzer({
|
|
79
|
+
manifest: {
|
|
80
|
+
sourceDir: './app',
|
|
81
|
+
targets: ['vue']
|
|
82
|
+
},
|
|
83
|
+
experimental: { ide: true }
|
|
84
|
+
})
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The IDE is a pre-built Vue app bundled into the plugin (no additional dependencies required). It includes:
|
|
88
|
+
|
|
89
|
+
- **File Explorer** with vscode-icons
|
|
90
|
+
- **Monaco Editor** with web language support (HTML, CSS, JS, TS, Vue, etc.)
|
|
91
|
+
- **Live Preview** powered by vrowzer (HMR via Web Worker + Service Worker)
|
|
92
|
+
- **File sync** via birpc WebSocket (edits are saved to local filesystem)
|
|
93
|
+
|
|
94
|
+
On `vite dev`, the IDE URL is printed in the console:
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
â Local: http://localhost:5173/
|
|
98
|
+
â Vrowzer IDE: http://localhost:5173/__vrowzer__/
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
You can also specify a custom port for the birpc WebSocket server:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
Vrowzer({
|
|
105
|
+
experimental: {
|
|
106
|
+
ide: { port: 7900 }
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## âī¸ Options
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
Vrowzer({
|
|
115
|
+
// Enable auto manifest generation
|
|
116
|
+
// Default: true
|
|
117
|
+
auto: true,
|
|
118
|
+
|
|
119
|
+
// Auto manifest options (used when auto: true)
|
|
120
|
+
manifest: {
|
|
121
|
+
// Directory to scan for source files (index.html, src/, public/)
|
|
122
|
+
// Default: Vite project root
|
|
123
|
+
sourceDir: './app',
|
|
124
|
+
// Package directory for node_modules resolution
|
|
125
|
+
// Default: Vite project root
|
|
126
|
+
pkgDir: '.',
|
|
127
|
+
// Package name(s) to include in nodeModules
|
|
128
|
+
// Default: all dependencies
|
|
129
|
+
targets: ['vue']
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
// Experimental features
|
|
133
|
+
experimental: {
|
|
134
|
+
// Enable browser IDE at /__vrowzer__/
|
|
135
|
+
// Default: false
|
|
136
|
+
ide: true // or { port: 7900 }
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
// Base path for the preview system
|
|
140
|
+
// Default: '/__preview__/'
|
|
141
|
+
basePath: '/__preview__/',
|
|
142
|
+
|
|
143
|
+
// Service Worker scope
|
|
144
|
+
// Default: '/'
|
|
145
|
+
serviceWorkerScope: '/',
|
|
146
|
+
|
|
147
|
+
// Service Worker version for cache management
|
|
148
|
+
// Default: 'SERVICE_WORKER_VERSION'
|
|
149
|
+
serviceWorkerVersion: 'my-app-v1',
|
|
150
|
+
|
|
151
|
+
// Explicit Service Worker entry file path
|
|
152
|
+
// Default: Resolved path to 'vrowzer/service-worker'
|
|
153
|
+
serviceWorkerEntry: 'vrowzer/service-worker',
|
|
154
|
+
|
|
155
|
+
// Worker-specific resolve settings
|
|
156
|
+
// Default: undefined
|
|
157
|
+
resolve: {
|
|
158
|
+
alias: [{ find: 'my-lib', replacement: '/libs/my-lib.js' }]
|
|
159
|
+
}
|
|
160
|
+
})
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
| Option | Type | Default | Description |
|
|
164
|
+
| ---------------------- | ---------------------------- | ----------------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
165
|
+
| `auto` | `boolean` | `true` | Enable auto manifest generation. Set `false` to use `VrowzerManifest()` manually. |
|
|
166
|
+
| `manifest` | `VrowzerManifestOptions` | `undefined` | Auto manifest options (sourceDir, pkgDir, targets). Used when `auto: true`. |
|
|
167
|
+
| `experimental` | `VrowzerExperimentalOptions` | `undefined` | Experimental features. Currently supports `ide`. |
|
|
168
|
+
| `basePath` | `string` | `'/__preview__/'` | Base path for the preview system. The Service Worker intercepts requests under this path. |
|
|
169
|
+
| `serviceWorkerScope` | `string` | `'/'` | The scope for the Service Worker registration. |
|
|
170
|
+
| `serviceWorkerVersion` | `string` | `'SERVICE_WORKER_VERSION'` | Version string for Service Worker cache management. |
|
|
171
|
+
| `serviceWorkerEntry` | `string` | Resolved path to `vrowzer/service-worker` | Explicit Service Worker entry file path. |
|
|
172
|
+
| `resolve` | `{ alias?: Alias[] }` | `undefined` | Worker-specific resolve settings passed to the internal Vite dev server. |
|
|
173
|
+
|
|
174
|
+
### `VrowzerManifestOptions`
|
|
175
|
+
|
|
176
|
+
| Option | Type | Default | Description |
|
|
177
|
+
| ----------- | ---------- | ----------------- | ----------------------------------------------------------------------- |
|
|
178
|
+
| `sourceDir` | `string` | Vite project root | Directory to scan for project source files (index.html, src/, public/). |
|
|
179
|
+
| `pkgDir` | `string` | Vite project root | Package directory for node_modules resolution. |
|
|
180
|
+
| `targets` | `string[]` | all dependencies | Package name(s) to include. Only these packages + transitive deps. |
|
|
181
|
+
|
|
182
|
+
### `VrowzerExperimentalOptions`
|
|
183
|
+
|
|
184
|
+
| Option | Type | Default | Description |
|
|
185
|
+
| ------ | ------------------------------ | ------- | ---------------------------------------------------------------- |
|
|
186
|
+
| `ide` | `boolean \| VrowzerIdeOptions` | `false` | Enable browser IDE at `/__vrowzer__/`. `true` uses all defaults. |
|
|
187
|
+
|
|
188
|
+
### `VrowzerIdeOptions`
|
|
189
|
+
|
|
190
|
+
| Option | Type | Default | Description |
|
|
191
|
+
| ------ | -------- | ------- | ------------------------------------ |
|
|
192
|
+
| `port` | `number` | auto | Port for the birpc WebSocket server. |
|
|
193
|
+
|
|
194
|
+
## đ Exported Plugins
|
|
195
|
+
|
|
196
|
+
### `Vrowzer(options?)`
|
|
197
|
+
|
|
198
|
+
Returns an array of Vite plugins that configure the environment for vrowzer:
|
|
199
|
+
|
|
200
|
+
#### 1. Auto Manifest Generation (`vrowzer:auto-manifest`)
|
|
201
|
+
|
|
202
|
+
When `auto: true` (default), automatically generates a vrowzer manifest in `configResolved`:
|
|
203
|
+
|
|
204
|
+
- Scans project source files (index.html, src/, public/)
|
|
205
|
+
- Collects npm dependencies from package.json
|
|
206
|
+
- Auto-bundles CJS packages to ESM using Rolldown
|
|
207
|
+
- Caches results in `node_modules/.vrowzer-manifest/` (keyed by deps + lockfile hash)
|
|
208
|
+
- Provides `virtual:vrowzer-manifest` virtual module with file contents resolved
|
|
209
|
+
|
|
210
|
+
#### 2. Worker Config Extraction & Prebundling (`vrowzer:config`)
|
|
211
|
+
|
|
212
|
+
Auto-extracts user plugins from `vite.config.ts` using OXC parser, then pre-bundles them with Rolldown for the Web Worker environment. The prebundled config is written to `node_modules/.vrowzer/config.bundled.mjs`.
|
|
213
|
+
|
|
214
|
+
- Resolves `@vrowzer/*` imports from the plugin's own dependency graph
|
|
215
|
+
- Inlines `readFileSync()` and `createRequire()` calls for Worker compatibility
|
|
216
|
+
- Maps `vite` imports to `@vrowzer/vite-dev-server/vite`
|
|
217
|
+
|
|
218
|
+
#### 3. Preview Guard Middleware (`vrowzer:server-middleware`)
|
|
219
|
+
|
|
220
|
+
Prevents Vite's SPA fallback from serving `index.html` for `basePath` requests when the Service Worker is not yet active. Returns a 503 with auto-retry instead.
|
|
221
|
+
|
|
222
|
+
#### 4. Process Global Injection
|
|
223
|
+
|
|
224
|
+
Injects `process` polyfill (`@vrowzer/node-polyfill/process`) for browser/Worker environments:
|
|
225
|
+
|
|
226
|
+
- **Dev mode**: Uses `@rollup/plugin-inject`
|
|
227
|
+
- **Build mode**: Uses Rolldown's native `transform.inject`
|
|
228
|
+
|
|
229
|
+
#### 5. Environment Configuration (`vrowzer:env`)
|
|
230
|
+
|
|
231
|
+
Sets up Vite configuration for the browser-based Vite dev server:
|
|
232
|
+
|
|
233
|
+
- **`resolve.alias`** â Maps Node.js built-in modules (`node:fs`, `node:path`, `node:events`, etc.) to browser-compatible polyfills
|
|
234
|
+
- **`worker.format`** â Set to `'es'` for ES Module workers
|
|
235
|
+
- **CORS headers** â `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: credentialless`, plus `Service-Worker-Allowed: /`
|
|
236
|
+
|
|
237
|
+
#### 6. Rolldown WASM Copy (`vrowzer:rolldown`)
|
|
238
|
+
|
|
239
|
+
Copies `@vrowzer/rolldown` WASM binary and sub-worker to `dist/assets/` during production builds.
|
|
240
|
+
|
|
241
|
+
#### 7. Service Worker Bundling
|
|
242
|
+
|
|
243
|
+
Uses `@vrowzer/unplugin-service-worker` to detect, bundle, and deploy the Service Worker with ESM format.
|
|
244
|
+
|
|
245
|
+
#### 8. Browser IDE (`vrowzer:ide`)
|
|
246
|
+
|
|
247
|
+
When `experimental.ide` is enabled (dev mode only):
|
|
248
|
+
|
|
249
|
+
- Serves a pre-built Vue app at `/__vrowzer__/` with File Explorer, Monaco Editor, and Preview
|
|
250
|
+
- Provides `/__vrowzer__/client.js` virtual module that imports `vrowzer` and `virtual:vrowzer-manifest`
|
|
251
|
+
- Starts a birpc WebSocket server for file sync (write-back edits to local filesystem)
|
|
252
|
+
- Watches for external file changes via Vite's chokidar watcher and pushes updates to the IDE
|
|
253
|
+
|
|
254
|
+
### `VrowzerManifest()`
|
|
255
|
+
|
|
256
|
+
Transforms `vrowzer-manifest.json` imports (with `?vrowzer` query suffix) by reading referenced files and embedding their contents into the imported object. Supports `files` and `nodeModules` fields. JS files in `nodeModules` are automatically minified with OXC (`minifySync`) to reduce bundle size.
|
|
257
|
+
|
|
258
|
+
Used in manual mode (`auto: false`) with a pre-generated `vrowzer-manifest.json` file.
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
// Import with ?vrowzer query to trigger content resolution
|
|
262
|
+
import manifest from './vrowzer-manifest.json?vrowzer'
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### `generateManifest(options, log?)`
|
|
266
|
+
|
|
267
|
+
Core manifest generation function, also available as a standalone export from `@vrowzer/vite-plugin/manifest-generate`. Used internally by the auto manifest plugin and by `scripts/generate-manifest.ts`.
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
import { generateManifest } from '@vrowzer/vite-plugin/manifest-generate'
|
|
271
|
+
|
|
272
|
+
const manifest = await generateManifest({
|
|
273
|
+
pkgDir: '/path/to/project',
|
|
274
|
+
sourceDir: '/path/to/project',
|
|
275
|
+
targets: ['vue'],
|
|
276
|
+
name: 'My App'
|
|
277
|
+
})
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## đ¤ Sponsors
|
|
281
|
+
|
|
282
|
+
<p align="center">
|
|
283
|
+
<a href="https://cdn.jsdelivr.net/gh/kazupon/sponsors/sponsors.svg">
|
|
284
|
+
<img alt="sponsor" src='https://cdn.jsdelivr.net/gh/kazupon/sponsors/sponsors.svg'/>
|
|
285
|
+
</a>
|
|
286
|
+
</p>
|
|
287
|
+
|
|
288
|
+
## ÂŠī¸ License
|
|
289
|
+
|
|
290
|
+
[MIT](http://opensource.org/licenses/MIT)
|