@gjsify/vite-plugin-gjsify 0.4.27

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/lib/index.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { type Plugin } from 'vite';
2
+ export interface GjsifyBrowserOptions {
3
+ /**
4
+ * Enable Deepkit type reflection (`@deepkit/type` runtime types). Off by
5
+ * default — the type compiler stays uninstalled until opted in, matching
6
+ * the lazy-loading contract of `@gjsify/rolldown-plugin-deepkit`.
7
+ */
8
+ reflection?: boolean;
9
+ /**
10
+ * Extra `resolve.alias` entries merged on top of the gjsify browser
11
+ * polyfill aliases (`process` / `assert` → `@gjsify/empty` / `@gjsify/assert`).
12
+ * User entries win over the defaults.
13
+ */
14
+ aliases?: Record<string, string>;
15
+ /**
16
+ * Extra package names to add to Vite's `optimizeDeps.exclude`, so Vite's
17
+ * esbuild dependency pre-bundler doesn't try to crawl GJS-shaped deps that
18
+ * import `gi://` / `@girs/*` (esbuild can't resolve those). `@gjsify/unit`
19
+ * is always excluded.
20
+ */
21
+ optimizeDepsExclude?: string[];
22
+ }
23
+ /**
24
+ * Returns the Vite plugin array that brings `gjsify build --app browser`'s
25
+ * browser-target transforms to a Vite project (dev + build), minus
26
+ * css-as-string. Spread it into a Vite config's `plugins`:
27
+ *
28
+ * ```ts
29
+ * import { defineConfig } from 'vite';
30
+ * import { gjsifyBrowser } from '@gjsify/vite-plugin-gjsify';
31
+ *
32
+ * export default defineConfig({
33
+ * plugins: [...gjsifyBrowser()],
34
+ * });
35
+ * ```
36
+ */
37
+ export declare function gjsifyBrowser(options?: GjsifyBrowserOptions): Plugin[];
38
+ export default gjsifyBrowser;
package/lib/index.js ADDED
@@ -0,0 +1,100 @@
1
+ // `@gjsify/vite-plugin-gjsify` — the "Vite-plugin track".
2
+ //
3
+ // This preset makes a web app's DEV experience (Vite dev server + HMR) and its
4
+ // Vite-driven `vite build` output match what `gjsify build --app browser`
5
+ // produces. It mirrors the Rolldown browser-target composition in
6
+ // `@gjsify/rolldown-plugin-gjsify`'s `app/browser.ts` so dual-target apps
7
+ // (the `examples/dom/*` shape, showcases' browser builds) get gjsify's browser
8
+ // transforms while still developing under Vite.
9
+ //
10
+ // What it composes (one-to-one with `--app browser`, EXCEPT css-as-string):
11
+ // - gjsImportsEmptyPlugin() → resolve `@girs/*` / `gi://*` to an empty
12
+ // module (GJS-only specifiers leak transitively
13
+ // via `@gjsify/unit` etc.; no browser equivalent)
14
+ // - blueprintPlugin() → compile `.blp` GNOME Blueprint files to XML
15
+ // - deepkitPlugin() → optional Deepkit type reflection (opt-in)
16
+ // - an inline Vite config hook supplying the browser-target resolve aliases,
17
+ // conditions, mainFields, defines and build target.
18
+ //
19
+ // DELIBERATELY OMITTED: cssAsStringPlugin.
20
+ // In `--app browser` (GJS/GTK builds) CSS is inlined into the JS bundle as a
21
+ // string because GTK consumes CSS as a string passed to its CSS provider.
22
+ // A *real* browser web app under Vite wants CSS to flow through Vite's NATIVE
23
+ // CSS pipeline (HMR, `<link>` extraction, PostCSS/Lightning CSS, CSS modules).
24
+ // Turning every `import './x.css'` into a JS string here would break that.
25
+ // css-as-string is a GJS/GTK build concern only, so this preset = Vite-dev
26
+ // parity with `gjsify build --app browser`, MINUS css-as-string.
27
+ //
28
+ // `aliasPlugin` from rolldown-plugin-gjsify is intentionally NOT used here
29
+ // (it is not part of that package's public API). Vite has a native
30
+ // `resolve.alias`, which is what the inline config hook below sets.
31
+ import { gjsImportsEmptyPlugin } from '@gjsify/rolldown-plugin-gjsify';
32
+ import blueprintPlugin from '@gjsify/vite-plugin-blueprint';
33
+ import { deepkitPlugin } from '@gjsify/rolldown-plugin-deepkit';
34
+ /**
35
+ * Returns the Vite plugin array that brings `gjsify build --app browser`'s
36
+ * browser-target transforms to a Vite project (dev + build), minus
37
+ * css-as-string. Spread it into a Vite config's `plugins`:
38
+ *
39
+ * ```ts
40
+ * import { defineConfig } from 'vite';
41
+ * import { gjsifyBrowser } from '@gjsify/vite-plugin-gjsify';
42
+ *
43
+ * export default defineConfig({
44
+ * plugins: [...gjsifyBrowser()],
45
+ * });
46
+ * ```
47
+ */
48
+ export function gjsifyBrowser(options = {}) {
49
+ // Standard Node → browser polyfill aliases. `@gjsify/unit` imports
50
+ // `node:assert` at the top level and references `process` inside an
51
+ // unreachable (browser) try/catch that the bundler still resolves
52
+ // statically — map both so the browser bundle stays resolvable.
53
+ const browserPolyfillAliases = {
54
+ process: '@gjsify/empty',
55
+ 'node:process': '@gjsify/empty',
56
+ assert: '@gjsify/assert',
57
+ 'node:assert': '@gjsify/assert',
58
+ };
59
+ const alias = {
60
+ ...browserPolyfillAliases,
61
+ ...(options.aliases ?? {}),
62
+ };
63
+ const optimizeDepsExclude = ['@gjsify/unit', ...(options.optimizeDepsExclude ?? [])];
64
+ const configPlugin = {
65
+ name: 'gjsify-browser-config',
66
+ config() {
67
+ return {
68
+ resolve: {
69
+ alias,
70
+ // Match `--app browser`'s `conditionNames` / `mainFields`
71
+ // so package `exports` / `browser` fields resolve the same
72
+ // way under Vite as they do under the Rolldown CLI.
73
+ conditions: ['import', 'browser'],
74
+ mainFields: ['browser', 'module', 'main'],
75
+ },
76
+ define: {
77
+ global: 'globalThis',
78
+ window: 'globalThis',
79
+ },
80
+ build: {
81
+ target: 'esnext',
82
+ },
83
+ optimizeDeps: {
84
+ // Vite's esbuild pre-bundler crawls deps eagerly and chokes
85
+ // on `gi://` / `@girs/*` imports in GJS-shaped packages.
86
+ // Excluding them defers resolution to the plugin pipeline,
87
+ // where gjsImportsEmptyPlugin handles the GJS specifiers.
88
+ exclude: optimizeDepsExclude,
89
+ },
90
+ };
91
+ },
92
+ };
93
+ return [
94
+ gjsImportsEmptyPlugin(),
95
+ blueprintPlugin(),
96
+ deepkitPlugin({ reflection: options.reflection }),
97
+ configPlugin,
98
+ ];
99
+ }
100
+ export default gjsifyBrowser;
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@gjsify/vite-plugin-gjsify",
3
+ "version": "0.4.27",
4
+ "description": "Vite plugin preset that mirrors `gjsify build --app browser` — dev (Vite/HMR) parity with the gjsify browser target.",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "module": "lib/index.js",
8
+ "types": "lib/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./lib/index.d.ts",
12
+ "default": "./lib/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "lib"
17
+ ],
18
+ "scripts": {
19
+ "clear": "rm -rf lib tsconfig.tsbuildinfo || exit 0",
20
+ "check": "tsc --noEmit",
21
+ "build": "tsc"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/gjsify/gjsify.git"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/gjsify/gjsify/issues"
29
+ },
30
+ "homepage": "https://github.com/gjsify/gjsify/tree/main/packages/infra/vite-plugin-gjsify#readme",
31
+ "keywords": [
32
+ "vite",
33
+ "rollup",
34
+ "rolldown",
35
+ "gjs",
36
+ "gtk",
37
+ "browser",
38
+ "gjsify"
39
+ ],
40
+ "license": "MIT",
41
+ "dependencies": {
42
+ "@gjsify/rolldown-plugin-deepkit": "workspace:^",
43
+ "@gjsify/rolldown-plugin-gjsify": "workspace:^",
44
+ "@gjsify/vite-plugin-blueprint": "workspace:^"
45
+ },
46
+ "peerDependencies": {
47
+ "vite": "^8.0.0"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "vite": {
51
+ "optional": true
52
+ }
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^25.9.1",
56
+ "typescript": "^6.0.3",
57
+ "vite": "^8.0.11"
58
+ }
59
+ }