@vantail/vite 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.
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The Vite plugin.
3
+ *
4
+ * `vantail dev` and `vantail build` apply this automatically, so a project does
5
+ * not need a `vite.config.ts` at all. Add it by hand when you already have
6
+ * one and want the same defaults:
7
+ *
8
+ * ```ts
9
+ * import { defineConfig } from "vite";
10
+ * import vantail from "@vantail/vite";
11
+ *
12
+ * export default defineConfig({ plugins: [vantail()] });
13
+ * ```
14
+ *
15
+ * It does four small things: point the build output at the `distDir` from
16
+ * `vantail.config.ts`, target the engines a webview actually has, expose the
17
+ * app's identity to application code, and warn when the page is opened in a
18
+ * normal browser where the native APIs cannot work.
19
+ */
20
+ import { type ParsedConfig } from "@vantail/shared/load";
21
+ import type { Plugin } from "vite";
22
+ export interface VantailPluginOptions {
23
+ /** Path to `vantail.config.ts`. Found automatically when omitted. */
24
+ config?: string;
25
+ /**
26
+ * A config that has already been loaded. `@vantail/cli` passes this so the
27
+ * config is not read and validated twice.
28
+ */
29
+ resolved?: {
30
+ config: ParsedConfig;
31
+ root: string;
32
+ };
33
+ }
34
+ /**
35
+ * Browser engines a Vantail app can actually run on: WKWebView on macOS,
36
+ * WebView2 on Windows, WebKitGTK on Linux. Pinned rather than left to Vite's
37
+ * default so a build cannot silently start emitting syntax that the oldest
38
+ * supported webview rejects.
39
+ */
40
+ export declare const WEBVIEW_TARGETS: string[];
41
+ export default function vantail(options?: VantailPluginOptions): Plugin;
42
+ export { vantail };
43
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAE/C,MAAM,WAAW,oBAAoB;IACnC,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,QAAQ,CAAC,EAAE;QAAE,MAAM,EAAE,YAAY,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CACnD;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UAAsC,CAAC;AAEnE,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,oBAAyB,GAAG,MAAM,CA4D1E;AAaD,OAAO,EAAE,OAAO,EAAE,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The Vite plugin.
3
+ *
4
+ * `vantail dev` and `vantail build` apply this automatically, so a project does
5
+ * not need a `vite.config.ts` at all. Add it by hand when you already have
6
+ * one and want the same defaults:
7
+ *
8
+ * ```ts
9
+ * import { defineConfig } from "vite";
10
+ * import vantail from "@vantail/vite";
11
+ *
12
+ * export default defineConfig({ plugins: [vantail()] });
13
+ * ```
14
+ *
15
+ * It does four small things: point the build output at the `distDir` from
16
+ * `vantail.config.ts`, target the engines a webview actually has, expose the
17
+ * app's identity to application code, and warn when the page is opened in a
18
+ * normal browser where the native APIs cannot work.
19
+ */
20
+ import { loadConfig } from "@vantail/shared/load";
21
+ /**
22
+ * Browser engines a Vantail app can actually run on: WKWebView on macOS,
23
+ * WebView2 on Windows, WebKitGTK on Linux. Pinned rather than left to Vite's
24
+ * default so a build cannot silently start emitting syntax that the oldest
25
+ * supported webview rejects.
26
+ */
27
+ export const WEBVIEW_TARGETS = ["es2022", "safari16", "chrome110"];
28
+ export default function vantail(options = {}) {
29
+ let resolved = options.resolved;
30
+ return {
31
+ name: "vantail",
32
+ async config(userConfig) {
33
+ if (!resolved) {
34
+ const loaded = await loadConfig({
35
+ cwd: userConfig.root ?? process.cwd(),
36
+ ...(options.config ? { path: options.config } : {}),
37
+ });
38
+ resolved = { config: loaded.config, root: loaded.root };
39
+ }
40
+ const { app, distDir } = resolved.config;
41
+ return {
42
+ // The custom protocol serves the resource directory as its root, so
43
+ // absolute asset URLs resolve exactly as they do on a web server.
44
+ base: "/",
45
+ clearScreen: false,
46
+ envPrefix: ["VITE_", "VANTAIL_"],
47
+ build: {
48
+ outDir: distDir ?? "dist",
49
+ target: WEBVIEW_TARGETS,
50
+ emptyOutDir: true,
51
+ },
52
+ server: {
53
+ // A moved port would leave the runtime pointing at nothing.
54
+ strictPort: true,
55
+ host: "127.0.0.1",
56
+ },
57
+ define: {
58
+ "import.meta.env.VANTAIL_APP_NAME": JSON.stringify(app.name),
59
+ "import.meta.env.VANTAIL_APP_VERSION": JSON.stringify(app.version ?? "0.0.0"),
60
+ "import.meta.env.VANTAIL_APP_IDENTIFIER": JSON.stringify(app.identifier),
61
+ },
62
+ };
63
+ },
64
+ transformIndexHtml: {
65
+ order: "pre",
66
+ handler(html, ctx) {
67
+ // Dev only: opening http://localhost:5173 in Chrome is a normal thing
68
+ // to do by accident, and the failure is otherwise mystifying.
69
+ if (!ctx.server || html.includes(NOTICE_MARKER))
70
+ return html;
71
+ return {
72
+ html,
73
+ tags: [
74
+ {
75
+ tag: "script",
76
+ injectTo: "head-prepend",
77
+ children: BROWSER_NOTICE,
78
+ },
79
+ ],
80
+ };
81
+ },
82
+ },
83
+ };
84
+ }
85
+ const NOTICE_MARKER = "[vantail] No native runtime detected";
86
+ const BROWSER_NOTICE = `
87
+ if (!window.__VANTAIL__) {
88
+ console.warn(
89
+ "[vantail] No native runtime detected. Native APIs will throw NO_RUNTIME.\\n" +
90
+ "This page is meant to be opened by \`vantail dev\`, not in a browser tab."
91
+ );
92
+ }
93
+ `.trim();
94
+ export { vantail };
95
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAqB,MAAM,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AqC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,IAAI,OAAO,CAAC;oBAC7E,wCAAwC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC;iBACzE;aACF,CAAC;QACJ,CAAC;QAED,kBAAkB,EAAE;YAClB,KAAK,EAAE,KAAK;YACZ,OAAO,CAAC,IAAY,EAAE,GAAyB;gBAC7C,sEAAsE;gBACtE,8DAA8D;gBAC9D,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC;oBAAE,OAAO,IAAI,CAAC;gBAC7D,OAAO;oBACL,IAAI;oBACJ,IAAI,EAAE;wBACJ;4BACE,GAAG,EAAE,QAAQ;4BACb,QAAQ,EAAE,cAAuB;4BACjC,QAAQ,EAAE,cAAc;yBACzB;qBACF;iBACF,CAAC;YACJ,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AAED,MAAM,aAAa,GAAG,sCAAsC,CAAC;AAE7D,MAAM,cAAc,GAAG;;;;;;;CAOtB,CAAC,IAAI,EAAE,CAAC;AAET,OAAO,EAAE,OAAO,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@vantail/vite",
3
+ "version": "0.1.0",
4
+ "description": "Vite plugin for Vantail applications.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Vantail/vantail.git",
9
+ "directory": "packages/vite"
10
+ },
11
+ "homepage": "https://github.com/Vantail/vantail",
12
+ "type": "module",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ }
21
+ },
22
+ "scripts": {
23
+ "build": "tsc -p tsconfig.json",
24
+ "typecheck": "tsc -p tsconfig.json --noEmit"
25
+ },
26
+ "dependencies": {
27
+ "@vantail/shared": "^0.1.0"
28
+ },
29
+ "peerDependencies": {
30
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "vite": "^8.0.0"
34
+ }
35
+ }