@gjsify/vite-plugin-gjsify 0.4.36 → 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.js +46 -7
- package/package.json +6 -5
package/lib/index.js
CHANGED
|
@@ -28,7 +28,8 @@
|
|
|
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';
|
|
34
35
|
import { ALIASES_NODE_FOR_NATIVESCRIPT } from '@gjsify/resolve-npm';
|
|
@@ -99,6 +100,30 @@ export function gjsifyBrowser(options = {}) {
|
|
|
99
100
|
];
|
|
100
101
|
}
|
|
101
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
|
+
}
|
|
102
127
|
/**
|
|
103
128
|
* Returns the Vite plugin array that brings `gjsify build --app nativescript`'s
|
|
104
129
|
* NS-target transforms to a Vite project (dev + build). Spread it into a
|
|
@@ -124,23 +149,32 @@ export function gjsifyNativescript(options = {}) {
|
|
|
124
149
|
nodePrefixAliases[bare] = target;
|
|
125
150
|
nodePrefixAliases[`node:${bare}`] = target;
|
|
126
151
|
}
|
|
127
|
-
const alias = {
|
|
128
|
-
...nodePrefixAliases,
|
|
129
|
-
...options.aliases,
|
|
130
|
-
};
|
|
131
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();
|
|
132
156
|
const configPlugin = {
|
|
133
157
|
name: 'gjsify-nativescript-config',
|
|
134
|
-
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();
|
|
135
164
|
return {
|
|
136
165
|
resolve: {
|
|
137
|
-
alias,
|
|
166
|
+
alias: { ...nodePrefixAliases, ...nativescriptCssTreeAlias(root), ...options.aliases },
|
|
138
167
|
conditions: ['import', 'nativescript'],
|
|
139
168
|
mainFields: ['nativescript', 'module', 'main'],
|
|
140
169
|
},
|
|
141
170
|
define: {
|
|
142
171
|
global: 'globalThis',
|
|
143
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 }),
|
|
144
178
|
},
|
|
145
179
|
build: {
|
|
146
180
|
target: 'esnext',
|
|
@@ -153,6 +187,11 @@ export function gjsifyNativescript(options = {}) {
|
|
|
153
187
|
};
|
|
154
188
|
return [
|
|
155
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 }),
|
|
156
195
|
// NO blueprintPlugin — Blueprint is GTK-specific
|
|
157
196
|
// NO cssAsStringPlugin — NS handles CSS via @nativescript/core
|
|
158
197
|
deepkitPlugin({ reflection: options.reflection }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/vite-plugin-gjsify",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.37",
|
|
4
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",
|
|
@@ -39,10 +39,11 @@
|
|
|
39
39
|
],
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@gjsify/
|
|
43
|
-
"@gjsify/
|
|
44
|
-
"@gjsify/rolldown-plugin-
|
|
45
|
-
"@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"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|
|
48
49
|
"vite": "^8.0.14"
|