Skip to content

Commit 92fcb87

Browse files
committed
fix(vite): global flags for hmr
1 parent 40788e3 commit 92fcb87

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/vite/helpers/main-entry.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ export function mainEntryPlugin(opts: { platform: 'ios' | 'android' | 'visionos'
6767
}
6868

6969
if (opts.hmrActive) {
70+
// Seed platform globals on the primary bundle realm using the same
71+
// CLI-derived platform that drives global-defines.ts. This ensures
72+
// HMR-delivered HTTP ESM modules can reliably read platform flags
73+
imports += `globalThis.__DEV__ = ${opts.isDevMode ? 'true' : 'false'};\n`;
74+
imports += `globalThis.__ANDROID__ = ${opts.platform === 'android' ? 'true' : 'false'};\n`;
75+
imports += `globalThis.__IOS__ = ${opts.platform === 'ios' ? 'true' : 'false'};\n`;
76+
imports += `globalThis.__VISIONOS__ = ${opts.platform === 'visionos' ? 'true' : 'false'};\n`;
77+
imports += `globalThis.__APPLE__ = ${opts.platform === 'ios' || opts.platform === 'visionos' ? 'true' : 'false'};\n`;
7078
// ---- Vendor manifest bootstrap ----
7179
// Use single self-contained vendor module to avoid extra imports affecting chunking
7280
imports += "import vendorManifest, { __nsVendorModuleMap } from '@nativescript/vendor';\n";

0 commit comments

Comments
 (0)