MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / nsHmrClientVitePlugin

Function nsHmrClientVitePlugin

packages/vite/hmr/server/vite-plugin.ts:8–47  ·  view source on GitHub ↗
(opts: { platform: string; verbose?: boolean })

Source from the content-addressed store, hash-verified

6const RESOLVED_ID = '\0' + VIRTUAL_ID;
7
8export function nsHmrClientVitePlugin(opts: { platform: string; verbose?: boolean }): Plugin {
9 let config: ResolvedConfig | undefined;
10
11 return {
12 name: 'ns-hmr-client',
13 configResolved(c) {
14 config = c;
15 },
16 resolveId(id) {
17 if (id === VIRTUAL_ID) return RESOLVED_ID;
18 return null;
19 },
20 load(id) {
21 if (id !== RESOLVED_ID) return null;
22
23 const clientPath = require.resolve('@nativescript/vite/hmr/client/index.js');
24
25 // Build ws url from Vite server info
26 let host = process.env.NS_HMR_HOST || (config?.server?.host as any);
27 // Android emu special-case
28 if (opts.platform === 'android' && (host === '0.0.0.0' || !host || host === true)) {
29 host = '10.0.2.2';
30 } else if (!host) {
31 host = 'localhost';
32 }
33 const port = Number(config?.server?.port || 5173);
34 const secure = !!config?.server?.https;
35 const protocol = secure ? 'wss' : 'ws';
36 const wsUrl = `${protocol}://${host}:${port}/ns-hmr`;
37
38 // Import client and start it with explicit ws URL
39 const banner = opts.verbose ? `console.log('[ns-hmr-client] starting client -> ${wsUrl} (HTTP loader enabled via __NS_HTTP_ORIGIN__)');` : '';
40 return `
41import startViteHMR from "${clientPath}";
42${banner}
43startViteHMR({ wsUrl: ${JSON.stringify(wsUrl)} });
44`;
45 },
46 };
47}

Callers 1

getHMRPluginsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected