@dormer/vite-plugin 0.0.0-stage → 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 CHANGED
@@ -1,3 +1,32 @@
1
- # Temporary Holding Version
1
+ # @dormer/vite-plugin
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Vite configuration a Dormer renderer needs, packaged as one plugin.
4
+
5
+ ```ts
6
+ // renderer/vite.config.ts
7
+ import { defineConfig } from "vite";
8
+ import { dormer } from "@dormer/vite-plugin";
9
+
10
+ export default defineConfig({ plugins: [dormer()] });
11
+ ```
12
+
13
+ What it sets (and why):
14
+
15
+ | Setting | Value | Reason |
16
+ |---|---|---|
17
+ | `base` | `"./"` | assets are loaded relative to `index.html` under `dormer://app/` |
18
+ | `build.target` | `"es2022"` | supported by WKWebView, WebView2 and WebKitGTK; smaller output |
19
+ | `build.outDir` | `<appRoot>/dist/renderer` | where `dormer build` and the host look for the renderer |
20
+ | `build.emptyOutDir` | `true` | the out dir is outside the Vite root |
21
+ | `define` | `import.meta.env.DORMER = true` | lets shared code know it is built for Dormer |
22
+ | `server.strictPort` (dev) | `true` | `dormer dev` passes the chosen URL to the host as `--dev-url` |
23
+ | `server.ws.host` (dev; `server.hmr.host` before Vite 8) | `"localhost"` | HMR websocket target the dev Content-Security-Policy allows |
24
+
25
+ It injects nothing into the HTML: the native host injects the `window.dormer` bridge at document
26
+ start, and `@dormer/renderer` wraps it.
27
+
28
+ `appRoot` is the nearest ancestor of the Vite root containing `dormer.config.json` (normally the
29
+ parent of `renderer/`). Options: `dormer({ appRoot, outDir, hmrHost })`.
30
+
31
+ Types for `import.meta.env.DORMER`: add `/// <reference types="@dormer/vite-plugin/client" />` to
32
+ your renderer's `vite-env.d.ts`.
package/client.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ // Type augmentation for renderers built with `@dormer/vite-plugin`.
2
+ // Reference it from your renderer's env declaration file:
3
+ // /// <reference types="@dormer/vite-plugin/client" />
4
+ interface ImportMetaEnv {
5
+ /** `true` when the page is built or served through `@dormer/vite-plugin`. */
6
+ readonly DORMER: boolean;
7
+ }
8
+ interface ImportMeta {
9
+ readonly env: ImportMetaEnv;
10
+ }
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ // src/index.ts
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ function findAppRoot(start) {
5
+ let dir = path.resolve(start);
6
+ for (; ; ) {
7
+ if (fs.existsSync(path.join(dir, "dormer.config.json"))) return dir;
8
+ const parent = path.dirname(dir);
9
+ if (parent === dir) return path.resolve(start);
10
+ dir = parent;
11
+ }
12
+ }
13
+ function dormer(options = {}) {
14
+ return {
15
+ name: "dormer",
16
+ config(userConfig, env) {
17
+ const viteRoot = path.resolve(userConfig.root ?? process.cwd());
18
+ const appRoot = options.appRoot ? path.resolve(options.appRoot) : findAppRoot(viteRoot);
19
+ const outDir = path.resolve(appRoot, options.outDir ?? "dist/renderer");
20
+ const config = {
21
+ base: "./",
22
+ build: { target: "es2022", outDir, emptyOutDir: true },
23
+ define: { "import.meta.env.DORMER": "true" }
24
+ };
25
+ if (env.command === "serve") {
26
+ const viteMajor = Number((this?.meta?.viteVersion ?? "0").split(".")[0]);
27
+ const host = options.hmrHost ?? "localhost";
28
+ config.server = { strictPort: true, ...viteMajor >= 8 ? { ws: { host } } : { hmr: { host } } };
29
+ }
30
+ return config;
31
+ }
32
+ };
33
+ }
34
+ var index_default = dormer;
35
+ export {
36
+ index_default as default,
37
+ dormer,
38
+ findAppRoot
39
+ };
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@dormer/vite-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Vite plugin for Dormer renderers: relative base, es2022 target, dist/renderer output, import.meta.env.DORMER",
5
+ "type": "module",
6
+ "license": "Apache-2.0 OR MIT",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./src/index.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./client": {
13
+ "types": "./client.d.ts"
14
+ }
15
+ },
16
+ "files": [
17
+ "README.md",
18
+ "client.d.ts",
19
+ "dist",
20
+ "src"
21
+ ],
22
+ "peerDependencies": {
23
+ "vite": ">=5.0.0"
24
+ },
25
+ "engines": {
26
+ "node": ">=22"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/veerareddyvishal144/dormer.git",
34
+ "directory": "packages/vite-plugin"
35
+ },
36
+ "scripts": {
37
+ "build": "node build.mjs",
38
+ "prepare": "node build.mjs"
39
+ },
40
+ "devDependencies": {
41
+ "esbuild": "^0.28.0"
42
+ }
43
+ }
package/src/index.ts ADDED
@@ -0,0 +1,64 @@
1
+ // @dormer/vite-plugin: the Vite configuration a Dormer renderer needs, as one plugin.
2
+ //
3
+ // Dormer serves the built renderer from `dormer://app/` (production) or from the Vite dev server
4
+ // (`dormer dev`). The plugin only sets configuration; it injects nothing into the HTML because
5
+ // the host injects the `window.dormer` bridge itself at document start.
6
+ //
7
+ // base: "./" assets resolve relative to index.html under dormer://app/
8
+ // build.target: "es2022" all three system WebViews support it; keeps output small
9
+ // build.outDir <appRoot>/dist/renderer, where `dormer build` and the host expect it
10
+ // define import.meta.env.DORMER === true
11
+ // server (dev only) strictPort so `dormer dev` can hand the host a stable --dev-url,
12
+ // HMR websocket pinned to a host name the dev CSP allows
13
+ // (server.ws.host on Vite 8+, server.hmr.host before)
14
+ import fs from "node:fs";
15
+ import path from "node:path";
16
+ import type { Plugin, UserConfig } from "vite";
17
+
18
+ export interface DormerPluginOptions {
19
+ /**
20
+ * Directory containing `dormer.config.json`. Default: the nearest ancestor of the Vite root
21
+ * that has one (usually `..` when the renderer lives in `<app>/renderer`), else the Vite root.
22
+ */
23
+ appRoot?: string;
24
+ /** Renderer output directory, relative to `appRoot`. Default `dist/renderer`. */
25
+ outDir?: string;
26
+ /** Host name the HMR websocket connects to in dev. Default `localhost`. */
27
+ hmrHost?: string;
28
+ }
29
+
30
+ /** Walks up from `start` looking for a directory that contains `dormer.config.json`. */
31
+ export function findAppRoot(start: string): string {
32
+ let dir = path.resolve(start);
33
+ for (;;) {
34
+ if (fs.existsSync(path.join(dir, "dormer.config.json"))) return dir;
35
+ const parent = path.dirname(dir);
36
+ if (parent === dir) return path.resolve(start);
37
+ dir = parent;
38
+ }
39
+ }
40
+
41
+ export function dormer(options: DormerPluginOptions = {}): Plugin {
42
+ return {
43
+ name: "dormer",
44
+ config(userConfig, env): UserConfig {
45
+ const viteRoot = path.resolve(userConfig.root ?? process.cwd());
46
+ const appRoot = options.appRoot ? path.resolve(options.appRoot) : findAppRoot(viteRoot);
47
+ const outDir = path.resolve(appRoot, options.outDir ?? "dist/renderer");
48
+ const config: UserConfig = {
49
+ base: "./",
50
+ build: { target: "es2022", outDir, emptyOutDir: true },
51
+ define: { "import.meta.env.DORMER": "true" },
52
+ };
53
+ if (env.command === "serve") {
54
+ // Vite 8 renamed the HMR websocket options from server.hmr.* to server.ws.*.
55
+ const viteMajor = Number(((this as unknown as { meta?: { viteVersion?: string } })?.meta?.viteVersion ?? "0").split(".")[0]);
56
+ const host = options.hmrHost ?? "localhost";
57
+ config.server = { strictPort: true, ...(viteMajor >= 8 ? { ws: { host } } : { hmr: { host } }) } as UserConfig["server"];
58
+ }
59
+ return config;
60
+ },
61
+ };
62
+ }
63
+
64
+ export default dormer;