@gjsify/vite-plugin-gjsify 0.4.35 → 0.4.37
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 +32 -0
- package/lib/index.js +101 -1
- package/package.json +10 -8
package/lib/index.d.ts
CHANGED
|
@@ -36,3 +36,35 @@ export interface GjsifyBrowserOptions {
|
|
|
36
36
|
*/
|
|
37
37
|
export declare function gjsifyBrowser(options?: GjsifyBrowserOptions): Plugin[];
|
|
38
38
|
export default gjsifyBrowser;
|
|
39
|
+
export interface GjsifyNativescriptOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Enable Deepkit type reflection. Off by default — matches gjsifyBrowser.
|
|
42
|
+
*/
|
|
43
|
+
reflection?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Extra `resolve.alias` entries merged on top of `ALIASES_NODE_FOR_NATIVESCRIPT`.
|
|
46
|
+
* User entries win over the defaults.
|
|
47
|
+
*/
|
|
48
|
+
aliases?: Record<string, string>;
|
|
49
|
+
/**
|
|
50
|
+
* Extra package names to add to Vite's `optimizeDeps.exclude`. `@gjsify/unit`
|
|
51
|
+
* is always excluded.
|
|
52
|
+
*/
|
|
53
|
+
optimizeDepsExclude?: string[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns the Vite plugin array that brings `gjsify build --app nativescript`'s
|
|
57
|
+
* NS-target transforms to a Vite project (dev + build). Spread it into a
|
|
58
|
+
* Vite config's `plugins`:
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { defineConfig } from 'vite';
|
|
62
|
+
* import { gjsifyNativescript } from '@gjsify/vite-plugin-gjsify';
|
|
63
|
+
* import nativescript from '@nativescript/vite';
|
|
64
|
+
*
|
|
65
|
+
* export default defineConfig({
|
|
66
|
+
* plugins: [nativescript(), ...gjsifyNativescript()],
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function gjsifyNativescript(options?: GjsifyNativescriptOptions): Plugin[];
|
package/lib/index.js
CHANGED
|
@@ -28,9 +28,11 @@
|
|
|
28
28
|
// `aliasPlugin` from rolldown-plugin-gjsify is intentionally NOT used here
|
|
29
29
|
// (it is not part of that package's public API). Vite has a native
|
|
30
30
|
// `resolve.alias`, which is what the inline config hook below sets.
|
|
31
|
-
import {
|
|
31
|
+
import { createRequire } from 'node:module';
|
|
32
|
+
import { gjsImportsEmptyPlugin, platformResolvePlugin, detectNativescriptPlatform, nativescriptPlatformDefines, } from '@gjsify/rolldown-plugin-gjsify';
|
|
32
33
|
import blueprintPlugin from '@gjsify/vite-plugin-blueprint';
|
|
33
34
|
import { deepkitPlugin } from '@gjsify/rolldown-plugin-deepkit';
|
|
35
|
+
import { ALIASES_NODE_FOR_NATIVESCRIPT } from '@gjsify/resolve-npm';
|
|
34
36
|
/**
|
|
35
37
|
* Returns the Vite plugin array that brings `gjsify build --app browser`'s
|
|
36
38
|
* browser-target transforms to a Vite project (dev + build), minus
|
|
@@ -98,3 +100,101 @@ export function gjsifyBrowser(options = {}) {
|
|
|
98
100
|
];
|
|
99
101
|
}
|
|
100
102
|
export default gjsifyBrowser;
|
|
103
|
+
/**
|
|
104
|
+
* `@nativescript/core`'s CSS parser pulls in `css-tree`, whose data modules
|
|
105
|
+
* (`data.js` / `data-patch.js` / `version.js`) load JSON via
|
|
106
|
+
* `createRequire(import.meta.url)('mdn-data/*.json' | '../package.json')` at
|
|
107
|
+
* module-evaluation time. Rolldown can't statically resolve those dynamic
|
|
108
|
+
* requires, so they survive into the bundle and throw on the NativeScript V8
|
|
109
|
+
* runtime ("Module evaluation promise rejected") — crashing every NS app that
|
|
110
|
+
* uses `@nativescript/core`'s styling. css-tree ships a self-contained
|
|
111
|
+
* `dist/csstree.esm.js` with the data inlined (no `createRequire`); aliasing the
|
|
112
|
+
* bare `css-tree` specifier to it keeps those requires out of the bundle.
|
|
113
|
+
*
|
|
114
|
+
* Resolved from the consuming project (`css-tree` is `@nativescript/core`'s
|
|
115
|
+
* transitive dep, not a direct one here). Returns no alias when css-tree isn't
|
|
116
|
+
* installed — a non-NS-core consumer keeps resolving `css-tree` normally.
|
|
117
|
+
*/
|
|
118
|
+
function nativescriptCssTreeAlias(fromDir) {
|
|
119
|
+
try {
|
|
120
|
+
const require = createRequire(import.meta.url);
|
|
121
|
+
return { 'css-tree': require.resolve('css-tree/dist/csstree.esm', { paths: [fromDir] }) };
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return {};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Returns the Vite plugin array that brings `gjsify build --app nativescript`'s
|
|
129
|
+
* NS-target transforms to a Vite project (dev + build). Spread it into a
|
|
130
|
+
* Vite config's `plugins`:
|
|
131
|
+
*
|
|
132
|
+
* ```ts
|
|
133
|
+
* import { defineConfig } from 'vite';
|
|
134
|
+
* import { gjsifyNativescript } from '@gjsify/vite-plugin-gjsify';
|
|
135
|
+
* import nativescript from '@nativescript/vite';
|
|
136
|
+
*
|
|
137
|
+
* export default defineConfig({
|
|
138
|
+
* plugins: [nativescript(), ...gjsifyNativescript()],
|
|
139
|
+
* });
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export function gjsifyNativescript(options = {}) {
|
|
143
|
+
// Bare Node-builtin + node:* prefix aliases. Both forms route to the same
|
|
144
|
+
// `@gjsify/<X>` target. Generated from `ALIASES_NODE_FOR_NATIVESCRIPT` so
|
|
145
|
+
// the single source-of-truth in `@gjsify/resolve-npm` drives every build,
|
|
146
|
+
// matching the Rolldown-side `app/nativescript.ts` composition.
|
|
147
|
+
const nodePrefixAliases = {};
|
|
148
|
+
for (const [bare, target] of Object.entries(ALIASES_NODE_FOR_NATIVESCRIPT)) {
|
|
149
|
+
nodePrefixAliases[bare] = target;
|
|
150
|
+
nodePrefixAliases[`node:${bare}`] = target;
|
|
151
|
+
}
|
|
152
|
+
const optimizeDepsExclude = ['@gjsify/unit', ...(options.optimizeDepsExclude ?? [])];
|
|
153
|
+
// Target platform from the env NS' CLI sets when it spawns the bundler
|
|
154
|
+
// (else `undefined` → `.native`-only resolution + neutral defines).
|
|
155
|
+
const platform = detectNativescriptPlatform();
|
|
156
|
+
const configPlugin = {
|
|
157
|
+
name: 'gjsify-nativescript-config',
|
|
158
|
+
config(userConfig, env) {
|
|
159
|
+
// `__DEV__` tracks Vite's mode (dev server vs `vite build`).
|
|
160
|
+
const dev = env?.mode !== 'production';
|
|
161
|
+
// Resolve css-tree from the project root (its dist is the consumer's
|
|
162
|
+
// transitive dep). User `aliases` are merged last so they win.
|
|
163
|
+
const root = userConfig?.root ?? process.cwd();
|
|
164
|
+
return {
|
|
165
|
+
resolve: {
|
|
166
|
+
alias: { ...nodePrefixAliases, ...nativescriptCssTreeAlias(root), ...options.aliases },
|
|
167
|
+
conditions: ['import', 'nativescript'],
|
|
168
|
+
mainFields: ['nativescript', 'module', 'main'],
|
|
169
|
+
},
|
|
170
|
+
define: {
|
|
171
|
+
global: 'globalThis',
|
|
172
|
+
// NO `window` define — NS apps have no DOM
|
|
173
|
+
//
|
|
174
|
+
// Standard NS compile-time platform flags, matching the
|
|
175
|
+
// Rolldown `--app nativescript` factory + the globals
|
|
176
|
+
// `@nativescript/vite` seeds in its main entry.
|
|
177
|
+
...nativescriptPlatformDefines(platform, { dev }),
|
|
178
|
+
},
|
|
179
|
+
build: {
|
|
180
|
+
target: 'esnext',
|
|
181
|
+
},
|
|
182
|
+
optimizeDeps: {
|
|
183
|
+
exclude: optimizeDepsExclude,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
return [
|
|
189
|
+
gjsImportsEmptyPlugin(),
|
|
190
|
+
// Platform-specific source variants (`*.android` / `*.ios` /
|
|
191
|
+
// `*.native`). A `resolveId` HOOK, NOT a `resolve.alias` — so it works
|
|
192
|
+
// under Vite 8 / Rolldown, where @nativescript/vite's function-based
|
|
193
|
+
// alias for the same feature is rejected.
|
|
194
|
+
platformResolvePlugin({ platform }),
|
|
195
|
+
// NO blueprintPlugin — Blueprint is GTK-specific
|
|
196
|
+
// NO cssAsStringPlugin — NS handles CSS via @nativescript/core
|
|
197
|
+
deepkitPlugin({ reflection: options.reflection }),
|
|
198
|
+
configPlugin,
|
|
199
|
+
];
|
|
200
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/vite-plugin-gjsify",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "Vite plugin
|
|
3
|
+
"version": "0.4.37",
|
|
4
|
+
"description": "Vite plugin presets mirroring `gjsify build --app browser` / `--app nativescript` — dev (Vite/HMR) parity with the gjsify CLI targets.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "lib/index.js",
|
|
@@ -39,12 +39,14 @@
|
|
|
39
39
|
],
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@gjsify/
|
|
43
|
-
"@gjsify/
|
|
44
|
-
"@gjsify/
|
|
42
|
+
"@gjsify/empty": "^0.4.37",
|
|
43
|
+
"@gjsify/resolve-npm": "^0.4.37",
|
|
44
|
+
"@gjsify/rolldown-plugin-deepkit": "^0.4.37",
|
|
45
|
+
"@gjsify/rolldown-plugin-gjsify": "^0.4.37",
|
|
46
|
+
"@gjsify/vite-plugin-blueprint": "^0.4.37"
|
|
45
47
|
},
|
|
46
48
|
"peerDependencies": {
|
|
47
|
-
"vite": "^8.0.
|
|
49
|
+
"vite": "^8.0.14"
|
|
48
50
|
},
|
|
49
51
|
"peerDependenciesMeta": {
|
|
50
52
|
"vite": {
|
|
@@ -53,7 +55,7 @@
|
|
|
53
55
|
},
|
|
54
56
|
"devDependencies": {
|
|
55
57
|
"@types/node": "^25.9.1",
|
|
56
|
-
"typescript": "^
|
|
57
|
-
"vite": "^8.0.
|
|
58
|
+
"typescript": "^5.9.3",
|
|
59
|
+
"vite": "^8.0.14"
|
|
58
60
|
}
|
|
59
61
|
}
|