@nativescript/vite 0.0.1

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.
Files changed (71) hide show
  1. package/dist/configuration/angular.d.ts +4 -0
  2. package/dist/configuration/angular.js +30 -0
  3. package/dist/configuration/base.d.ts +13 -0
  4. package/dist/configuration/base.js +228 -0
  5. package/dist/configuration/old-without-merge-base.d.ts +13 -0
  6. package/dist/configuration/old-without-merge-base.js +249 -0
  7. package/dist/configuration/react.d.ts +4 -0
  8. package/dist/configuration/react.js +85 -0
  9. package/dist/configuration/solid.d.ts +4 -0
  10. package/dist/configuration/solid.js +48 -0
  11. package/dist/configuration/vue.d.ts +4 -0
  12. package/dist/configuration/vue.js +45 -0
  13. package/dist/helpers/commonjs-plugins.d.ts +6 -0
  14. package/dist/helpers/commonjs-plugins.js +75 -0
  15. package/dist/helpers/config-as-json.d.ts +2 -0
  16. package/dist/helpers/config-as-json.js +35 -0
  17. package/dist/helpers/css-tree.d.ts +4 -0
  18. package/dist/helpers/css-tree.js +21 -0
  19. package/dist/helpers/dynamic-import-plugin.d.ts +4 -0
  20. package/dist/helpers/dynamic-import-plugin.js +62 -0
  21. package/dist/helpers/flavor.d.ts +5 -0
  22. package/dist/helpers/flavor.js +40 -0
  23. package/dist/helpers/global-defines.d.ts +14 -0
  24. package/dist/helpers/global-defines.js +18 -0
  25. package/dist/helpers/main-entry.d.ts +5 -0
  26. package/dist/helpers/main-entry.js +75 -0
  27. package/dist/helpers/module-resolution.d.ts +1 -0
  28. package/dist/helpers/module-resolution.js +17 -0
  29. package/dist/helpers/nativescript-package-resolver.d.ts +5 -0
  30. package/dist/helpers/nativescript-package-resolver.js +139 -0
  31. package/dist/helpers/ns-cli-plugins.d.ts +17 -0
  32. package/dist/helpers/ns-cli-plugins.js +128 -0
  33. package/dist/helpers/package-platform-aliases.d.ts +4 -0
  34. package/dist/helpers/package-platform-aliases.js +83 -0
  35. package/dist/helpers/project.d.ts +23 -0
  36. package/dist/helpers/project.js +28 -0
  37. package/dist/helpers/resolver.d.ts +4 -0
  38. package/dist/helpers/resolver.js +31 -0
  39. package/dist/helpers/ts-config-paths.d.ts +4 -0
  40. package/dist/helpers/ts-config-paths.js +241 -0
  41. package/dist/helpers/utils.d.ts +23 -0
  42. package/dist/helpers/utils.js +94 -0
  43. package/dist/helpers/workers.d.ts +20 -0
  44. package/dist/helpers/workers.js +86 -0
  45. package/dist/hmr/hmr-angular.d.ts +1 -0
  46. package/dist/hmr/hmr-angular.js +34 -0
  47. package/dist/hmr/hmr-bridge.d.ts +18 -0
  48. package/dist/hmr/hmr-bridge.js +154 -0
  49. package/dist/hmr/hmr-client.d.ts +5 -0
  50. package/dist/hmr/hmr-client.js +93 -0
  51. package/dist/hmr/hmr-server.d.ts +20 -0
  52. package/dist/hmr/hmr-server.js +179 -0
  53. package/dist/index.d.ts +5 -0
  54. package/dist/index.js +5 -0
  55. package/dist/polyfills/mdn-data-at-rules.d.ts +7 -0
  56. package/dist/polyfills/mdn-data-at-rules.js +7 -0
  57. package/dist/polyfills/mdn-data-properties.d.ts +7 -0
  58. package/dist/polyfills/mdn-data-properties.js +7 -0
  59. package/dist/polyfills/mdn-data-syntaxes.d.ts +7 -0
  60. package/dist/polyfills/mdn-data-syntaxes.js +7 -0
  61. package/dist/polyfills/module.d.ts +17 -0
  62. package/dist/polyfills/module.js +29 -0
  63. package/dist/shims/react-reconciler-constants.d.ts +14 -0
  64. package/dist/shims/react-reconciler-constants.js +20 -0
  65. package/dist/shims/react-reconciler.d.ts +8 -0
  66. package/dist/shims/react-reconciler.js +14 -0
  67. package/dist/shims/set-value.d.ts +4 -0
  68. package/dist/shims/set-value.js +21 -0
  69. package/dist/transformers/NativeClass/index.d.ts +5 -0
  70. package/dist/transformers/NativeClass/index.js +46 -0
  71. package/package.json +31 -0
@@ -0,0 +1,4 @@
1
+ import { type UserConfig } from "vite";
2
+ export declare const angularConfig: ({ mode }: {
3
+ mode: any;
4
+ }) => UserConfig;
@@ -0,0 +1,30 @@
1
+ import { mergeConfig } from "vite";
2
+ import path from "path";
3
+ import angular from "@analogjs/vite-plugin-angular";
4
+ import { baseConfig } from "./base.js";
5
+ const plugins = [
6
+ // Allow external html template changes to trigger hot reload: Make .ts files depend on their .html templates
7
+ {
8
+ name: "angular-template-deps",
9
+ transform(code, id) {
10
+ // For .ts files that reference templateUrl, add the .html file as a dependency
11
+ if (id.endsWith(".ts") && code.includes("templateUrl")) {
12
+ const templateUrlMatch = code.match(/templateUrl:\s*['"]\.\/(.*?\.html)['"]/);
13
+ if (templateUrlMatch) {
14
+ const htmlPath = path.resolve(path.dirname(id), templateUrlMatch[1]);
15
+ // Add the HTML file as a dependency so Vite watches it
16
+ this.addWatchFile(htmlPath);
17
+ }
18
+ }
19
+ return null;
20
+ },
21
+ },
22
+ angular({
23
+ liveReload: false, // Disable live reload in favor of HMR
24
+ }),
25
+ ];
26
+ export const angularConfig = ({ mode }) => {
27
+ return mergeConfig(baseConfig({ mode }), {
28
+ plugins,
29
+ });
30
+ };
@@ -0,0 +1,13 @@
1
+ import type { UserConfig } from "vite";
2
+ export declare const baseConfig: ({ mode, skipCommonjsPackages, customCommonjsPlugins, commonjsIgnoreList, optimizeDeps, }: {
3
+ mode: string;
4
+ skipCommonjsPackages?: string[];
5
+ customCommonjsPlugins?: {
6
+ name: string;
7
+ enforce: string;
8
+ resolveId(id: any): any;
9
+ load(id: any): string;
10
+ }[];
11
+ commonjsIgnoreList?: string[];
12
+ optimizeDeps?: string[];
13
+ }) => UserConfig;
@@ -0,0 +1,228 @@
1
+ import path from "path";
2
+ import minimist from "minimist";
3
+ import commonjs from "@rollup/plugin-commonjs";
4
+ import NativeScriptPlugin from "../helpers/resolver.js";
5
+ import nsConfigAsJsonPlugin from "../helpers/config-as-json.js";
6
+ import { getProjectRootPath } from "../helpers/project.js";
7
+ import { aliasCssTree } from "../helpers/css-tree.js";
8
+ import { packagePlatformAliases } from "../helpers/package-platform-aliases.js";
9
+ import { getGlobalDefines } from "../helpers/global-defines.js";
10
+ import { getWorkerPlugins, workerUrlPlugin } from "../helpers/workers.js";
11
+ import { getTsConfigData } from "../helpers/ts-config-paths.js";
12
+ import { commonjsPlugins } from "../helpers/commonjs-plugins.js";
13
+ import { nativescriptPackageResolver } from "../helpers/nativescript-package-resolver.js";
14
+ import { hmrPlugin, cliPlugin } from "../helpers/ns-cli-plugins.js";
15
+ import { dynamicImportPlugin } from "../helpers/dynamic-import-plugin.js";
16
+ import { mainEntryPlugin } from "../helpers/main-entry.js";
17
+ import { determineProjectFlavor } from "../helpers/flavor.js";
18
+ const debugViteLogs = !!process.env.VITE_DEBUG_PATHS;
19
+ const projectRoot = getProjectRootPath();
20
+ export const baseConfig = ({ mode, skipCommonjsPackages, customCommonjsPlugins, commonjsIgnoreList, optimizeDeps, }) => {
21
+ const platform = mode;
22
+ const targetMode = process.env.production ? "production" : "development";
23
+ const cliArgs = minimist(process.argv.slice(2), { "--": true });
24
+ const cliFlags = (cliArgs["--"] || []).reduce((obj, flag) => {
25
+ // remove env prefix
26
+ const [rawKey, ...rest] = flag.replace(/^--env\./, "").split("=");
27
+ obj[rawKey] = rest.length === 0 ? true : rest.join("=");
28
+ return obj;
29
+ }, {});
30
+ console.log("cliFlags:", cliFlags);
31
+ const debug = !!cliFlags.viteDebug || !!process.env.DEBUG || targetMode === "development";
32
+ if (debug) {
33
+ console.log("--------------");
34
+ console.log("Vite config mode:", mode);
35
+ console.log("Target mode:", targetMode);
36
+ console.log("Platform:", platform);
37
+ console.log("--------------");
38
+ }
39
+ const flavor = determineProjectFlavor();
40
+ console.log(`Building for ${flavor}.`);
41
+ // Create TypeScript aliases with platform support
42
+ const tsConfigData = getTsConfigData(debugViteLogs, platform);
43
+ // Common resolve configuration for both main and worker builds
44
+ const resolveConfig = {
45
+ // ensures Vite prefers ESM entry‑points
46
+ mainFields: ["module", "main"],
47
+ // Make sure ESM conditions win during resolution
48
+ conditions: ["module", "import", "browser", "default"],
49
+ // use this with merge config instead or could list common dedupes in base here altogether
50
+ dedupe: ["@nativescript/core", "nativescript-vue", "vue"],
51
+ // Alias "@" and "~" to your src directory for cleaner imports
52
+ alias: [
53
+ ...aliasCssTree,
54
+ // 1) Catch exactly `~/package.json` → virtual module (MUST be first!)
55
+ { find: /^~\/package\.json$/, replacement: "~/package.json" },
56
+ // TypeScript path aliases from tsconfig.json
57
+ ...tsConfigData.aliases,
58
+ // Generic platform resolution for any npm package
59
+ packagePlatformAliases(tsConfigData, platform, skipCommonjsPackages, debugViteLogs),
60
+ // 2) Catch everything else under "~/" → your src/
61
+ { find: /^~\/(.*)$/, replacement: path.resolve(projectRoot, "src/$1") },
62
+ // optional: "@" → src/
63
+ { find: "@", replacement: path.resolve(projectRoot, "src") },
64
+ ],
65
+ extensions: [
66
+ ".ios.tsx",
67
+ ".android.tsx",
68
+ ".tsx",
69
+ ".ios.jsx",
70
+ ".android.jsx",
71
+ ".jsx",
72
+ ".ios.ts",
73
+ ".android.ts",
74
+ ".ts",
75
+ ".ios.js",
76
+ ".android.js",
77
+ ".js",
78
+ ".mjs",
79
+ ".json",
80
+ ],
81
+ preserveSymlinks: true,
82
+ };
83
+ // Common define configuration for both main and worker builds
84
+ const defineConfig = getGlobalDefines(platform, targetMode);
85
+ return {
86
+ resolve: resolveConfig,
87
+ define: defineConfig,
88
+ // Vite's built-in solution for CommonJS/ESM compatibility issues
89
+ optimizeDeps: {
90
+ // Force pre-bundling of problematic CommonJS packages
91
+ include: [
92
+ // "source-map-js",
93
+ "@valor/nativescript-websockets",
94
+ // React and related packages for proper module resolution
95
+ "react",
96
+ "react-reconciler",
97
+ "react-nativescript",
98
+ ...(optimizeDeps || []),
99
+ // Add any other problematic packages here
100
+ ],
101
+ // Handle Node.js built-ins and other edge cases
102
+ esbuildOptions: {
103
+ // Pass the same conditions to ESBuild for css-tree compatibility
104
+ conditions: ["module", "import", "browser", "default"],
105
+ // Define globals for Node.js built-ins if needed
106
+ define: {
107
+ global: "globalThis",
108
+ },
109
+ },
110
+ },
111
+ plugins: [
112
+ // TODO: make flavor plugins dynamic
113
+ // ...flavorPlugins,
114
+ ...commonjsPlugins,
115
+ ...(customCommonjsPlugins || []),
116
+ // Platform-specific package resolver - MUST come before commonjs plugin
117
+ nativescriptPackageResolver(platform),
118
+ // Simplified CommonJS handling - let Vite's optimizeDeps do the heavy lifting
119
+ commonjs({
120
+ include: [/node_modules/],
121
+ // Force specific problematic modules to be treated as CommonJS
122
+ requireReturnsDefault: "auto",
123
+ defaultIsModuleExports: "auto",
124
+ transformMixedEsModules: true,
125
+ // Ignore optional dependencies that are meant to fail gracefully
126
+ ignore: [
127
+ "@nativescript/android",
128
+ "@nativescript/ios",
129
+ ...(commonjsIgnoreList || []),
130
+ ],
131
+ }),
132
+ nsConfigAsJsonPlugin(),
133
+ NativeScriptPlugin({ platform }),
134
+ mainEntryPlugin(cliFlags, debug),
135
+ // NativeScript HMR integration - track changes for incremental builds
136
+ hmrPlugin(targetMode),
137
+ // NativeScript CLI integration - enhanced IPC communication for HMR
138
+ cliPlugin(targetMode, cliFlags),
139
+ dynamicImportPlugin(),
140
+ // Transform Vite worker URLs to NativeScript format AFTER bundling
141
+ workerUrlPlugin(),
142
+ ],
143
+ css: {
144
+ postcss: "./postcss.config.js",
145
+ },
146
+ // Development server configuration for HMR
147
+ server: targetMode === "development"
148
+ ? {
149
+ hmr: {
150
+ // Enable Vite's built-in HMR
151
+ port: 24678, // Different port to avoid conflicts with our custom WebSocket
152
+ },
153
+ // CORS for development
154
+ cors: true,
155
+ }
156
+ : {},
157
+ // Configure worker builds to bundle everything into standalone workers
158
+ worker: {
159
+ format: "es",
160
+ plugins: () => getWorkerPlugins(platform),
161
+ rollupOptions: {
162
+ // Don't externalize anything - bundle everything into the worker
163
+ external: [],
164
+ output: {
165
+ // Inline all dynamic imports to create standalone bundle
166
+ inlineDynamicImports: true,
167
+ },
168
+ },
169
+ },
170
+ build: {
171
+ target: "esnext",
172
+ minify: !debug,
173
+ // Generate source maps for debugging
174
+ // Note: just disabling for now until can hook up to angular vite/analog plugin
175
+ sourcemap: false, //debug,
176
+ // Disable module preloading to avoid browser APIs
177
+ modulePreload: false,
178
+ // Optimize for development speed
179
+ ...(targetMode === "development" && {
180
+ // Faster builds in development
181
+ reportCompressedSize: false,
182
+ chunkSizeWarningLimit: 2000,
183
+ }),
184
+ commonjsOptions: {
185
+ include: [/node_modules/],
186
+ },
187
+ rollupOptions: {
188
+ input: "virtual:entry-with-polyfills",
189
+ output: {
190
+ dir: path.resolve(projectRoot, "dist"),
191
+ format: "es", // Emit ES modules (.mjs)
192
+ entryFileNames: "bundle.mjs", // <- no hash here
193
+ chunkFileNames: (chunk) => {
194
+ if (chunk.name === "vendor")
195
+ return "vendor.mjs";
196
+ // Place worker files at root level, not in assets/
197
+ if (chunk.name && chunk.name.includes("worker")) {
198
+ return "[name]-[hash].js";
199
+ }
200
+ return "[name]-[hash].mjs";
201
+ },
202
+ assetFileNames: "assets/[name][extname]",
203
+ // Create single vendor chunk - no separate globals chunk to avoid circular deps
204
+ manualChunks(id) {
205
+ if (id.includes("node_modules")) {
206
+ // Note: this is work in progress on best setup
207
+ // Keep polyfills and Zone-dependent packages in main bundle to ensure correct execution order
208
+ if ([
209
+ "@nativescript/core",
210
+ "@nativescript/angular",
211
+ "@nativescript/zone-js",
212
+ "@valor/nativescript-websockets",
213
+ "make-error",
214
+ // "source-map-js",
215
+ "zone.js",
216
+ "/globals",
217
+ "/polyfills",
218
+ ].includes(id)) {
219
+ return undefined; // Keep in main bundle
220
+ }
221
+ return "vendor";
222
+ }
223
+ },
224
+ },
225
+ },
226
+ },
227
+ };
228
+ };
@@ -0,0 +1,13 @@
1
+ import type { UserConfig } from "vite";
2
+ export declare const baseConfig: ({ mode, skipCommonjsPackages, customCommonjsPlugins, commonjsIgnoreList, optimizeDeps, }: {
3
+ mode: string;
4
+ skipCommonjsPackages?: string[];
5
+ customCommonjsPlugins?: {
6
+ name: string;
7
+ enforce: string;
8
+ resolveId(id: any): any;
9
+ load(id: any): string;
10
+ }[];
11
+ commonjsIgnoreList?: string[];
12
+ optimizeDeps?: string[];
13
+ }) => UserConfig;
@@ -0,0 +1,249 @@
1
+ import path from "path";
2
+ import minimist from "minimist";
3
+ import commonjs from "@rollup/plugin-commonjs";
4
+ import NativeScriptPlugin from "../helpers/resolver.js";
5
+ import nsConfigAsJsonPlugin from "../helpers/config-as-json.js";
6
+ import { getProjectRootPath } from "../helpers/project.js";
7
+ import { aliasCssTree } from "../helpers/css-tree.js";
8
+ import { packagePlatformAliases } from "../helpers/package-platform-aliases.js";
9
+ import { getGlobalDefines } from "../helpers/global-defines.js";
10
+ import { getWorkerPlugins, workerUrlPlugin } from "../helpers/workers.js";
11
+ import { getTsConfigData } from "../helpers/ts-config-paths.js";
12
+ import { commonjsPlugins } from "../helpers/commonjs-plugins.js";
13
+ import { nativescriptPackageResolver } from "../helpers/nativescript-package-resolver.js";
14
+ import { hmrPlugin, cliPlugin } from "../helpers/ns-cli-plugins.js";
15
+ import { dynamicImportPlugin } from "../helpers/dynamic-import-plugin.js";
16
+ import { mainEntryPlugin } from "../helpers/main-entry.js";
17
+ import { determineProjectFlavor } from "../helpers/flavor.js";
18
+ const debugViteLogs = !!process.env.VITE_DEBUG_PATHS;
19
+ const projectRoot = getProjectRootPath();
20
+ // NOTE: just testing with angular directly temporarily
21
+ // change this to pick up environment for flavors dynamically
22
+ // import { angularPlugins } from "./angular.js";
23
+ // import { getReactPlugins } from "./react.js";
24
+ // import { getSolidPlugins } from "./solid.js";
25
+ // import { vuePlugins } from "./vue.js";
26
+ export const baseConfig = ({ mode, skipCommonjsPackages, customCommonjsPlugins, commonjsIgnoreList, optimizeDeps, }) => {
27
+ const platform = mode;
28
+ const targetMode = process.env.production ? "production" : "development";
29
+ const cliArgs = minimist(process.argv.slice(2), { "--": true });
30
+ const cliFlags = (cliArgs["--"] || []).reduce((obj, flag) => {
31
+ // remove env prefix
32
+ const [rawKey, ...rest] = flag.replace(/^--env\./, "").split("=");
33
+ obj[rawKey] = rest.length === 0 ? true : rest.join("=");
34
+ return obj;
35
+ }, {});
36
+ console.log("cliFlags:", cliFlags);
37
+ const debug = !!cliFlags.viteDebug || !!process.env.DEBUG || targetMode === "development";
38
+ if (debug) {
39
+ console.log("--------------");
40
+ console.log("Vite config mode:", mode);
41
+ console.log("Target mode:", targetMode);
42
+ console.log("Platform:", platform);
43
+ console.log("--------------");
44
+ }
45
+ const flavor = determineProjectFlavor();
46
+ console.log(`Building with ${flavor}`);
47
+ // let flavorPlugins: any[] = [];
48
+ switch (flavor) {
49
+ // case "angular":
50
+ // flavorPlugins = angularPlugins;
51
+ // break;
52
+ // case "react":
53
+ // flavorPlugins = getReactPlugins(!debug);
54
+ // break;
55
+ // case "vue":
56
+ // flavorPlugins = vuePlugins;
57
+ // break;
58
+ // case "solid":
59
+ // flavorPlugins = getSolidPlugins(!debug);
60
+ // break;
61
+ }
62
+ // Create TypeScript aliases with platform support
63
+ const tsConfigData = getTsConfigData(debugViteLogs, platform);
64
+ // Common resolve configuration for both main and worker builds
65
+ const resolveConfig = {
66
+ // ensures Vite prefers ESM entry‑points
67
+ mainFields: ["module", "main"],
68
+ // Make sure ESM conditions win during resolution
69
+ conditions: ["module", "import", "browser", "default"],
70
+ // use this with merge config instead or could list common dedupes in base here altogether
71
+ dedupe: ["@nativescript/core", "nativescript-vue", "vue"],
72
+ // Alias "@" and "~" to your src directory for cleaner imports
73
+ alias: [
74
+ ...aliasCssTree,
75
+ // 1) Catch exactly `~/package.json` → virtual module (MUST be first!)
76
+ { find: /^~\/package\.json$/, replacement: "~/package.json" },
77
+ // TypeScript path aliases from tsconfig.json
78
+ ...tsConfigData.aliases,
79
+ // Generic platform resolution for any npm package
80
+ packagePlatformAliases(tsConfigData, platform, skipCommonjsPackages, debugViteLogs),
81
+ // 2) Catch everything else under "~/" → your src/
82
+ { find: /^~\/(.*)$/, replacement: path.resolve(projectRoot, "src/$1") },
83
+ // optional: "@" → src/
84
+ { find: "@", replacement: path.resolve(projectRoot, "src") },
85
+ ],
86
+ extensions: [
87
+ ".ios.tsx",
88
+ ".android.tsx",
89
+ ".tsx",
90
+ ".ios.jsx",
91
+ ".android.jsx",
92
+ ".jsx",
93
+ ".ios.ts",
94
+ ".android.ts",
95
+ ".ts",
96
+ ".ios.js",
97
+ ".android.js",
98
+ ".js",
99
+ ".mjs",
100
+ ".json",
101
+ ],
102
+ preserveSymlinks: true,
103
+ };
104
+ // Common define configuration for both main and worker builds
105
+ const defineConfig = getGlobalDefines(platform, targetMode);
106
+ return {
107
+ resolve: resolveConfig,
108
+ define: defineConfig,
109
+ // Vite's built-in solution for CommonJS/ESM compatibility issues
110
+ optimizeDeps: {
111
+ // Force pre-bundling of problematic CommonJS packages
112
+ include: [
113
+ // "source-map-js",
114
+ "@valor/nativescript-websockets",
115
+ // React and related packages for proper module resolution
116
+ "react",
117
+ "react-reconciler",
118
+ "react-nativescript",
119
+ ...(optimizeDeps || []),
120
+ // Add any other problematic packages here
121
+ ],
122
+ // Handle Node.js built-ins and other edge cases
123
+ esbuildOptions: {
124
+ // Pass the same conditions to ESBuild for css-tree compatibility
125
+ conditions: ["module", "import", "browser", "default"],
126
+ // Define globals for Node.js built-ins if needed
127
+ define: {
128
+ global: "globalThis",
129
+ },
130
+ },
131
+ },
132
+ plugins: [
133
+ // TODO: make flavor plugins dynamic
134
+ // ...flavorPlugins,
135
+ ...commonjsPlugins,
136
+ ...(customCommonjsPlugins || []),
137
+ // Platform-specific package resolver - MUST come before commonjs plugin
138
+ nativescriptPackageResolver(platform),
139
+ // Simplified CommonJS handling - let Vite's optimizeDeps do the heavy lifting
140
+ commonjs({
141
+ include: [/node_modules/],
142
+ // Force specific problematic modules to be treated as CommonJS
143
+ requireReturnsDefault: "auto",
144
+ defaultIsModuleExports: "auto",
145
+ transformMixedEsModules: true,
146
+ // Ignore optional dependencies that are meant to fail gracefully
147
+ ignore: [
148
+ "@nativescript/android",
149
+ "@nativescript/ios",
150
+ ...(commonjsIgnoreList || []),
151
+ ],
152
+ }),
153
+ nsConfigAsJsonPlugin(),
154
+ NativeScriptPlugin({ platform }),
155
+ mainEntryPlugin(cliFlags, debug),
156
+ // NativeScript HMR integration - track changes for incremental builds
157
+ hmrPlugin(targetMode),
158
+ // NativeScript CLI integration - enhanced IPC communication for HMR
159
+ cliPlugin(targetMode, cliFlags),
160
+ dynamicImportPlugin(),
161
+ // Transform Vite worker URLs to NativeScript format AFTER bundling
162
+ workerUrlPlugin(),
163
+ ],
164
+ css: {
165
+ postcss: "./postcss.config.js",
166
+ },
167
+ // Development server configuration for HMR
168
+ server: targetMode === "development"
169
+ ? {
170
+ hmr: {
171
+ // Enable Vite's built-in HMR
172
+ port: 24678, // Different port to avoid conflicts with our custom WebSocket
173
+ },
174
+ // CORS for development
175
+ cors: true,
176
+ }
177
+ : {},
178
+ // Configure worker builds to bundle everything into standalone workers
179
+ worker: {
180
+ format: "es",
181
+ plugins: () => getWorkerPlugins(platform),
182
+ rollupOptions: {
183
+ // Don't externalize anything - bundle everything into the worker
184
+ external: [],
185
+ output: {
186
+ // Inline all dynamic imports to create standalone bundle
187
+ inlineDynamicImports: true,
188
+ },
189
+ },
190
+ },
191
+ build: {
192
+ target: "esnext",
193
+ minify: !debug,
194
+ // Generate source maps for debugging
195
+ // Note: just disabling for now until can hook up to angular vite/analog plugin
196
+ sourcemap: false, //debug,
197
+ // Disable module preloading to avoid browser APIs
198
+ modulePreload: false,
199
+ // Optimize for development speed
200
+ ...(targetMode === "development" && {
201
+ // Faster builds in development
202
+ reportCompressedSize: false,
203
+ chunkSizeWarningLimit: 2000,
204
+ }),
205
+ commonjsOptions: {
206
+ include: [/node_modules/],
207
+ },
208
+ rollupOptions: {
209
+ input: "virtual:entry-with-polyfills",
210
+ output: {
211
+ dir: path.resolve(projectRoot, "dist"),
212
+ format: "es", // Emit ES modules (.mjs)
213
+ entryFileNames: "bundle.mjs", // <- no hash here
214
+ chunkFileNames: (chunk) => {
215
+ if (chunk.name === "vendor")
216
+ return "vendor.mjs";
217
+ // Place worker files at root level, not in assets/
218
+ if (chunk.name && chunk.name.includes("worker")) {
219
+ return "[name]-[hash].js";
220
+ }
221
+ return "[name]-[hash].mjs";
222
+ },
223
+ assetFileNames: "assets/[name][extname]",
224
+ // Create single vendor chunk - no separate globals chunk to avoid circular deps
225
+ manualChunks(id) {
226
+ if (id.includes("node_modules")) {
227
+ // Note: this is work in progress on best setup
228
+ // Keep polyfills and Zone-dependent packages in main bundle to ensure correct execution order
229
+ if ([
230
+ "@nativescript/core",
231
+ "@nativescript/angular",
232
+ "@nativescript/zone-js",
233
+ "@valor/nativescript-websockets",
234
+ "make-error",
235
+ // "source-map-js",
236
+ "zone.js",
237
+ "/globals",
238
+ "/polyfills",
239
+ ].includes(id)) {
240
+ return undefined; // Keep in main bundle
241
+ }
242
+ return "vendor";
243
+ }
244
+ },
245
+ },
246
+ },
247
+ },
248
+ };
249
+ };
@@ -0,0 +1,4 @@
1
+ import { type UserConfig } from "vite";
2
+ export declare const reactConfig: ({ mode }: {
3
+ mode: any;
4
+ }) => UserConfig;
@@ -0,0 +1,85 @@
1
+ import alias from "@rollup/plugin-alias";
2
+ import { fileURLToPath } from "node:url";
3
+ import { dirname, resolve } from "node:path";
4
+ import { mergeConfig } from "vite";
5
+ import { baseConfig } from "./base.js";
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = dirname(__filename);
8
+ const plugins = [
9
+ {
10
+ ...alias({
11
+ entries: {
12
+ // Essential aliases for React NativeScript compatibility
13
+ // Only alias react-dom related imports, NOT React itself
14
+ "react-dom": "react-nativescript",
15
+ "react-dom/client": "react-nativescript",
16
+ "react-dom/server": "react-nativescript",
17
+ // Handle react-reconciler exports issue
18
+ // This addresses the "DefaultEventPriority" and "LegacyRoot" not exported errors
19
+ "react-reconciler/constants": resolve(__dirname, "../shims/react-reconciler-constants.js"),
20
+ // Additional React ecosystem compatibility
21
+ "react-reconciler/src/ReactFiberHostConfig": "react-nativescript/dist/client/HostConfig",
22
+ // Fix React reconciler namespace issue
23
+ "react-reconciler": resolve(__dirname, "../shims/react-reconciler.js"),
24
+ // Additional shims
25
+ "set-value": resolve(__dirname, "../shims/set-value.js"),
26
+ },
27
+ }),
28
+ enforce: "pre",
29
+ },
30
+ {
31
+ name: "react-nativescript-resolver",
32
+ resolveId(id) {
33
+ // Ensure React core exports are properly resolved
34
+ if (id === "react") {
35
+ return { id: "react", external: false };
36
+ }
37
+ },
38
+ load(id) {
39
+ // Handle React module loading to ensure all exports are available
40
+ if (id === "react") {
41
+ return `
42
+ // Re-export all React exports to ensure they're available
43
+ import * as React from 'react/index.js';
44
+
45
+ // Explicitly export the commonly used React APIs
46
+ export const {
47
+ Component,
48
+ PureComponent,
49
+ Fragment,
50
+ createElement,
51
+ createRef,
52
+ forwardRef,
53
+ useState,
54
+ useEffect,
55
+ useContext,
56
+ useReducer,
57
+ useCallback,
58
+ useMemo,
59
+ useRef,
60
+ useImperativeHandle,
61
+ useLayoutEffect,
62
+ useDebugValue,
63
+ createContext,
64
+ Children,
65
+ cloneElement,
66
+ isValidElement,
67
+ version,
68
+ __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
69
+ } = React;
70
+
71
+ // Export everything else
72
+ export * from 'react/index.js';
73
+
74
+ // Default export
75
+ export default React;
76
+ `;
77
+ }
78
+ },
79
+ },
80
+ ];
81
+ export const reactConfig = ({ mode }) => {
82
+ return mergeConfig(baseConfig({ mode }), {
83
+ plugins,
84
+ });
85
+ };
@@ -0,0 +1,4 @@
1
+ import { type UserConfig } from "vite";
2
+ export declare const solidConfig: ({ mode }: {
3
+ mode: any;
4
+ }) => UserConfig;