@nativescript/vite 0.0.1-alpha.7 → 0.0.2

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 (265) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +44 -0
  3. package/{dist/configuration → configuration}/angular.d.ts +1 -1
  4. package/configuration/angular.js +480 -0
  5. package/configuration/angular.js.map +1 -0
  6. package/configuration/base.d.ts +5 -0
  7. package/configuration/base.js +494 -0
  8. package/configuration/base.js.map +1 -0
  9. package/configuration/javascript.d.ts +4 -0
  10. package/configuration/javascript.js +151 -0
  11. package/configuration/javascript.js.map +1 -0
  12. package/{dist/configuration → configuration}/react.d.ts +1 -1
  13. package/{dist/configuration → configuration}/react.js +18 -17
  14. package/configuration/react.js.map +1 -0
  15. package/{dist/configuration → configuration}/solid.d.ts +1 -1
  16. package/{dist/configuration → configuration}/solid.js +17 -16
  17. package/configuration/solid.js.map +1 -0
  18. package/configuration/typescript.d.ts +4 -0
  19. package/configuration/typescript.js +175 -0
  20. package/configuration/typescript.js.map +1 -0
  21. package/{dist/configuration → configuration}/vue.d.ts +1 -1
  22. package/configuration/vue.js +163 -0
  23. package/configuration/vue.js.map +1 -0
  24. package/helpers/angular-linker.d.ts +13 -0
  25. package/helpers/angular-linker.js +181 -0
  26. package/helpers/angular-linker.js.map +1 -0
  27. package/helpers/cli-flags.d.ts +1 -0
  28. package/helpers/cli-flags.js +15 -0
  29. package/helpers/cli-flags.js.map +1 -0
  30. package/{dist/helpers → helpers}/commonjs-plugins.js +14 -13
  31. package/helpers/commonjs-plugins.js.map +1 -0
  32. package/{dist/helpers → helpers}/config-as-json.d.ts +1 -1
  33. package/{dist/helpers → helpers}/config-as-json.js +7 -6
  34. package/helpers/config-as-json.js.map +1 -0
  35. package/helpers/css-platform-plugin.d.ts +10 -0
  36. package/helpers/css-platform-plugin.js +76 -0
  37. package/helpers/css-platform-plugin.js.map +1 -0
  38. package/helpers/css-tree.js +22 -0
  39. package/helpers/css-tree.js.map +1 -0
  40. package/{dist/helpers → helpers}/dynamic-import-plugin.js +8 -7
  41. package/helpers/dynamic-import-plugin.js.map +1 -0
  42. package/helpers/esbuild-platform-resolver.d.ts +14 -0
  43. package/helpers/esbuild-platform-resolver.js +93 -0
  44. package/helpers/esbuild-platform-resolver.js.map +1 -0
  45. package/{dist/helpers → helpers}/external-configs.js +2 -1
  46. package/helpers/external-configs.js.map +1 -0
  47. package/{dist/helpers → helpers}/flavor.d.ts +1 -0
  48. package/helpers/flavor.js +51 -0
  49. package/helpers/flavor.js.map +1 -0
  50. package/{dist/helpers → helpers}/global-defines.d.ts +11 -3
  51. package/helpers/global-defines.js +24 -0
  52. package/helpers/global-defines.js.map +1 -0
  53. package/helpers/logging.d.ts +13 -0
  54. package/helpers/logging.js +111 -0
  55. package/helpers/logging.js.map +1 -0
  56. package/helpers/main-entry.d.ts +10 -0
  57. package/helpers/main-entry.js +215 -0
  58. package/helpers/main-entry.js.map +1 -0
  59. package/{dist/helpers → helpers}/module-resolution.js +4 -3
  60. package/helpers/module-resolution.js.map +1 -0
  61. package/{dist/helpers → helpers}/module-runner-patch.d.ts +1 -1
  62. package/{dist/helpers → helpers}/module-runner-patch.js +10 -12
  63. package/helpers/module-runner-patch.js.map +1 -0
  64. package/helpers/nativeclass-transform.d.ts +7 -0
  65. package/helpers/nativeclass-transform.js +158 -0
  66. package/helpers/nativeclass-transform.js.map +1 -0
  67. package/helpers/nativeclass-transformer-plugin.d.ts +5 -0
  68. package/helpers/nativeclass-transformer-plugin.js +23 -0
  69. package/helpers/nativeclass-transformer-plugin.js.map +1 -0
  70. package/{dist/helpers → helpers}/nativescript-package-resolver.js +18 -17
  71. package/helpers/nativescript-package-resolver.js.map +1 -0
  72. package/{dist/helpers → helpers}/ns-cli-plugins.d.ts +6 -1
  73. package/{dist/helpers → helpers}/ns-cli-plugins.js +31 -51
  74. package/helpers/ns-cli-plugins.js.map +1 -0
  75. package/helpers/package-platform-aliases.d.ts +10 -0
  76. package/{dist/helpers → helpers}/package-platform-aliases.js +18 -22
  77. package/helpers/package-platform-aliases.js.map +1 -0
  78. package/helpers/postcss-platform-config.d.ts +13 -0
  79. package/helpers/postcss-platform-config.js +97 -0
  80. package/helpers/postcss-platform-config.js.map +1 -0
  81. package/helpers/prelink-angular.d.ts +2 -0
  82. package/helpers/prelink-angular.js +117 -0
  83. package/helpers/prelink-angular.js.map +1 -0
  84. package/helpers/preserve-imports.js +38 -0
  85. package/helpers/preserve-imports.js.map +1 -0
  86. package/{dist/helpers → helpers}/project.js +2 -4
  87. package/helpers/project.js.map +1 -0
  88. package/helpers/resolver.d.ts +4 -0
  89. package/{dist/helpers → helpers}/resolver.js +7 -6
  90. package/helpers/resolver.js.map +1 -0
  91. package/helpers/theme-core-plugins.d.ts +14 -0
  92. package/helpers/theme-core-plugins.js +121 -0
  93. package/helpers/theme-core-plugins.js.map +1 -0
  94. package/helpers/ts-config-paths.d.ts +10 -0
  95. package/{dist/helpers → helpers}/ts-config-paths.js +70 -71
  96. package/helpers/ts-config-paths.js.map +1 -0
  97. package/{dist/helpers → helpers}/utils.js +14 -27
  98. package/helpers/utils.js.map +1 -0
  99. package/{dist/helpers → helpers}/workers.js +15 -16
  100. package/helpers/workers.js.map +1 -0
  101. package/{dist/hmr → hmr/client}/css-handler.js +18 -17
  102. package/hmr/client/css-handler.js.map +1 -0
  103. package/hmr/client/index.d.ts +13 -0
  104. package/hmr/client/index.js +1550 -0
  105. package/hmr/client/index.js.map +1 -0
  106. package/hmr/client/utils.d.ts +38 -0
  107. package/hmr/client/utils.js +426 -0
  108. package/hmr/client/utils.js.map +1 -0
  109. package/hmr/entry-runtime.d.ts +8 -0
  110. package/hmr/entry-runtime.js +135 -0
  111. package/hmr/entry-runtime.js.map +1 -0
  112. package/hmr/frameworks/angular/server/strategy.d.ts +2 -0
  113. package/hmr/frameworks/angular/server/strategy.js +101 -0
  114. package/hmr/frameworks/angular/server/strategy.js.map +1 -0
  115. package/hmr/frameworks/vue/client/index.d.ts +22 -0
  116. package/hmr/frameworks/vue/client/index.js +1537 -0
  117. package/hmr/frameworks/vue/client/index.js.map +1 -0
  118. package/hmr/frameworks/vue/server/compiler.d.ts +11 -0
  119. package/hmr/frameworks/vue/server/compiler.js +26 -0
  120. package/hmr/frameworks/vue/server/compiler.js.map +1 -0
  121. package/hmr/frameworks/vue/server/sfc-transforms.d.ts +14 -0
  122. package/hmr/frameworks/vue/server/sfc-transforms.js +282 -0
  123. package/hmr/frameworks/vue/server/sfc-transforms.js.map +1 -0
  124. package/hmr/frameworks/vue/server/strategy.d.ts +2 -0
  125. package/hmr/frameworks/vue/server/strategy.js +273 -0
  126. package/hmr/frameworks/vue/server/strategy.js.map +1 -0
  127. package/hmr/helpers/ast-extract.d.ts +6 -0
  128. package/hmr/helpers/ast-extract.js +72 -0
  129. package/hmr/helpers/ast-extract.js.map +1 -0
  130. package/hmr/helpers/ast-normalizer.d.ts +7 -0
  131. package/hmr/helpers/ast-normalizer.js +772 -0
  132. package/hmr/helpers/ast-normalizer.js.map +1 -0
  133. package/hmr/helpers/babel.d.ts +3 -0
  134. package/hmr/helpers/babel.js +17 -0
  135. package/hmr/helpers/babel.js.map +1 -0
  136. package/hmr/helpers/sanitize.d.ts +6 -0
  137. package/hmr/helpers/sanitize.js +55 -0
  138. package/hmr/helpers/sanitize.js.map +1 -0
  139. package/hmr/helpers/vendor-rewrite.d.ts +1 -0
  140. package/hmr/helpers/vendor-rewrite.js +35 -0
  141. package/hmr/helpers/vendor-rewrite.js.map +1 -0
  142. package/hmr/server/compiler.d.ts +2 -0
  143. package/hmr/server/compiler.js +75 -0
  144. package/hmr/server/compiler.js.map +1 -0
  145. package/hmr/server/constants.d.ts +14 -0
  146. package/hmr/server/constants.js +23 -0
  147. package/hmr/server/constants.js.map +1 -0
  148. package/hmr/server/core-sanitize.d.ts +32 -0
  149. package/hmr/server/core-sanitize.js +134 -0
  150. package/hmr/server/core-sanitize.js.map +1 -0
  151. package/hmr/server/framework-strategy.d.ts +68 -0
  152. package/hmr/server/framework-strategy.js +2 -0
  153. package/hmr/server/framework-strategy.js.map +1 -0
  154. package/hmr/server/index.d.ts +5 -0
  155. package/hmr/server/index.js +19 -0
  156. package/hmr/server/index.js.map +1 -0
  157. package/hmr/server/vite-plugin.d.ts +5 -0
  158. package/{dist/hmr/plugins/plugin-vue.js → hmr/server/vite-plugin.js} +13 -15
  159. package/hmr/server/vite-plugin.js.map +1 -0
  160. package/hmr/server/websocket.d.ts +15 -0
  161. package/hmr/server/websocket.js +5528 -0
  162. package/hmr/server/websocket.js.map +1 -0
  163. package/hmr/shared/runtime/http-only-boot.d.ts +1 -0
  164. package/hmr/shared/runtime/http-only-boot.js +107 -0
  165. package/hmr/shared/runtime/http-only-boot.js.map +1 -0
  166. package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
  167. package/hmr/shared/runtime/root-placeholder.js +142 -0
  168. package/hmr/shared/runtime/root-placeholder.js.map +1 -0
  169. package/hmr/shared/runtime/vendor-bootstrap.d.ts +1 -0
  170. package/hmr/shared/runtime/vendor-bootstrap.js +134 -0
  171. package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -0
  172. package/hmr/shared/vendor/manifest-loader.d.ts +9 -0
  173. package/hmr/shared/vendor/manifest-loader.js +38 -0
  174. package/hmr/shared/vendor/manifest-loader.js.map +1 -0
  175. package/hmr/shared/vendor/manifest.d.ts +34 -0
  176. package/hmr/shared/vendor/manifest.js +787 -0
  177. package/hmr/shared/vendor/manifest.js.map +1 -0
  178. package/hmr/shared/vendor/registry.d.ts +9 -0
  179. package/hmr/shared/vendor/registry.js +62 -0
  180. package/hmr/shared/vendor/registry.js.map +1 -0
  181. package/hmr/vendor-bootstrap.d.ts +3 -0
  182. package/hmr/vendor-bootstrap.js +32 -0
  183. package/hmr/vendor-bootstrap.js.map +1 -0
  184. package/{dist/index.d.ts → index.d.ts} +2 -0
  185. package/{dist/index.js → index.js} +3 -0
  186. package/index.js.map +1 -0
  187. package/package.json +39 -31
  188. package/{dist/polyfills → polyfills}/mdn-data-at-rules.js +1 -0
  189. package/polyfills/mdn-data-at-rules.js.map +1 -0
  190. package/{dist/polyfills → polyfills}/mdn-data-properties.js +1 -0
  191. package/polyfills/mdn-data-properties.js.map +1 -0
  192. package/{dist/polyfills → polyfills}/mdn-data-syntaxes.js +1 -0
  193. package/polyfills/mdn-data-syntaxes.js.map +1 -0
  194. package/{dist/polyfills → polyfills}/module.js +1 -0
  195. package/polyfills/module.js.map +1 -0
  196. package/runtime/core-aliases-early.d.ts +1 -0
  197. package/runtime/core-aliases-early.js +334 -0
  198. package/runtime/core-aliases-early.js.map +1 -0
  199. package/shims/angular-animations-stub.d.ts +8 -0
  200. package/shims/angular-animations-stub.js +14 -0
  201. package/shims/angular-animations-stub.js.map +1 -0
  202. package/{dist/shims → shims}/node-module.js +3 -2
  203. package/shims/node-module.js.map +1 -0
  204. package/{dist/shims → shims}/react-reconciler-constants.js +2 -1
  205. package/shims/react-reconciler-constants.js.map +1 -0
  206. package/{dist/shims → shims}/react-reconciler.js +1 -0
  207. package/shims/react-reconciler.js.map +1 -0
  208. package/{dist/shims → shims}/set-value.js +5 -1
  209. package/shims/set-value.js.map +1 -0
  210. package/transformers/NativeClass/index.d.ts +2 -0
  211. package/transformers/NativeClass/index.js +222 -0
  212. package/transformers/NativeClass/index.js.map +1 -0
  213. package/dist/configuration/angular.js +0 -30
  214. package/dist/configuration/base.d.ts +0 -4
  215. package/dist/configuration/base.js +0 -386
  216. package/dist/configuration/vue.js +0 -45
  217. package/dist/helpers/css-tree.js +0 -21
  218. package/dist/helpers/flavor.js +0 -40
  219. package/dist/helpers/global-defines.js +0 -20
  220. package/dist/helpers/main-entry-hmr-includes.d.ts +0 -1
  221. package/dist/helpers/main-entry-hmr-includes.js +0 -18
  222. package/dist/helpers/main-entry.d.ts +0 -5
  223. package/dist/helpers/main-entry.js +0 -82
  224. package/dist/helpers/package-platform-aliases.d.ts +0 -4
  225. package/dist/helpers/preserve-imports.js +0 -19
  226. package/dist/helpers/resolver.d.ts +0 -4
  227. package/dist/helpers/ts-config-paths.d.ts +0 -4
  228. package/dist/hmr/client-vue.d.ts +0 -6
  229. package/dist/hmr/client-vue.js +0 -585
  230. package/dist/hmr/component-tracker.d.ts +0 -23
  231. package/dist/hmr/component-tracker.js +0 -193
  232. package/dist/hmr/message-handler.d.ts +0 -1
  233. package/dist/hmr/message-handler.js +0 -590
  234. package/dist/hmr/nsv-hooks.d.ts +0 -2
  235. package/dist/hmr/nsv-hooks.js +0 -481
  236. package/dist/hmr/plugins/index.d.ts +0 -1
  237. package/dist/hmr/plugins/index.js +0 -16
  238. package/dist/hmr/plugins/plugin-vue.d.ts +0 -2
  239. package/dist/hmr/plugins/websocket-vue.d.ts +0 -2
  240. package/dist/hmr/plugins/websocket-vue.js +0 -911
  241. package/dist/hmr/runtime-vue.d.ts +0 -13
  242. package/dist/hmr/runtime-vue.js +0 -2306
  243. package/dist/hmr/types.d.ts +0 -24
  244. package/dist/hmr/types.js +0 -2
  245. package/dist/transformers/NativeClass/index.d.ts +0 -5
  246. package/dist/transformers/NativeClass/index.js +0 -46
  247. /package/{dist/helpers → helpers}/commonjs-plugins.d.ts +0 -0
  248. /package/{dist/helpers → helpers}/css-tree.d.ts +0 -0
  249. /package/{dist/helpers → helpers}/dynamic-import-plugin.d.ts +0 -0
  250. /package/{dist/helpers → helpers}/external-configs.d.ts +0 -0
  251. /package/{dist/helpers → helpers}/module-resolution.d.ts +0 -0
  252. /package/{dist/helpers → helpers}/nativescript-package-resolver.d.ts +0 -0
  253. /package/{dist/helpers → helpers}/preserve-imports.d.ts +0 -0
  254. /package/{dist/helpers → helpers}/project.d.ts +0 -0
  255. /package/{dist/helpers → helpers}/utils.d.ts +0 -0
  256. /package/{dist/helpers → helpers}/workers.d.ts +0 -0
  257. /package/{dist/hmr → hmr/client}/css-handler.d.ts +0 -0
  258. /package/{dist/polyfills → polyfills}/mdn-data-at-rules.d.ts +0 -0
  259. /package/{dist/polyfills → polyfills}/mdn-data-properties.d.ts +0 -0
  260. /package/{dist/polyfills → polyfills}/mdn-data-syntaxes.d.ts +0 -0
  261. /package/{dist/polyfills → polyfills}/module.d.ts +0 -0
  262. /package/{dist/shims → shims}/node-module.d.ts +0 -0
  263. /package/{dist/shims → shims}/react-reconciler-constants.d.ts +0 -0
  264. /package/{dist/shims → shims}/react-reconciler.d.ts +0 -0
  265. /package/{dist/shims → shims}/set-value.d.ts +0 -0
@@ -1,386 +0,0 @@
1
- import { mergeConfig, createLogger } from "vite";
2
- import path from "path";
3
- import { existsSync, readFileSync } from "fs";
4
- import { createRequire } from "node:module";
5
- import { pathToFileURL } from "node:url";
6
- import minimist from "minimist";
7
- import commonjs from "@rollup/plugin-commonjs";
8
- import replace from "@rollup/plugin-replace";
9
- import { viteStaticCopy } from "vite-plugin-static-copy";
10
- import NativeScriptPlugin from "../helpers/resolver.js";
11
- import nsConfigAsJsonPlugin from "../helpers/config-as-json.js";
12
- import { getProjectRootPath } from "../helpers/project.js";
13
- import { aliasCssTree } from "../helpers/css-tree.js";
14
- import { packagePlatformAliases } from "../helpers/package-platform-aliases.js";
15
- import { getGlobalDefines } from "../helpers/global-defines.js";
16
- import { getWorkerPlugins, workerUrlPlugin } from "../helpers/workers.js";
17
- import { getTsConfigData } from "../helpers/ts-config-paths.js";
18
- import { commonjsPlugins } from "../helpers/commonjs-plugins.js";
19
- import { nativescriptPackageResolver } from "../helpers/nativescript-package-resolver.js";
20
- import { cliPlugin } from "../helpers/ns-cli-plugins.js";
21
- import { dynamicImportPlugin } from "../helpers/dynamic-import-plugin.js";
22
- import { mainEntryPlugin } from "../helpers/main-entry.js";
23
- import { determineProjectFlavor } from "../helpers/flavor.js";
24
- import { preserveImportsPlugin } from "../helpers/preserve-imports.js";
25
- import { externalConfigMerges, applyExternalConfigs, } from "../helpers/external-configs.js";
26
- import { getHMRPlugins } from "../hmr/plugins/index.js";
27
- const require = createRequire(import.meta.url);
28
- const distOutputFolder = process.env.NS_VITE_DIST_DIR || ".ns-vite-build";
29
- const verboseLogs = !!process.env.VITE_DEBUG_LOGS;
30
- // HMR dev server options with socket
31
- const useHttps = process.env.NS_HTTPS === "1" || process.env.NS_HTTPS === "true";
32
- const projectRoot = getProjectRootPath();
33
- /**
34
- * Plugins can define nativescript.vite.mjs
35
- * which export Vite configs to merge into the base config.
36
- */
37
- applyExternalConfigs();
38
- export const baseConfig = ({ mode }) => {
39
- const targetMode = mode === "development" ? "development" : "production";
40
- const cliArgs = minimist(process.argv.slice(2), { "--": true });
41
- const cliFlags = (cliArgs["--"] || []).reduce((obj, flag) => {
42
- // remove env prefix
43
- const [rawKey, ...rest] = flag.replace(/^--env\./, "").split("=");
44
- obj[rawKey] = rest.length === 0 ? true : rest.join("=");
45
- return obj;
46
- }, {});
47
- // console.log("cliFlags:", cliFlags);
48
- const isDevMode = targetMode === "development";
49
- const debug = !!process.env.DEBUG || isDevMode;
50
- const hmrActive = isDevMode && !!cliFlags.hmr;
51
- let platform = cliFlags.platform;
52
- if (cliFlags.android) {
53
- platform = "android";
54
- }
55
- else if (cliFlags.ios) {
56
- platform = "ios";
57
- }
58
- else if (cliFlags.visionos) {
59
- platform = "visionos";
60
- }
61
- if (debug) {
62
- console.log("--------------");
63
- // console.log("Vite config mode:", mode);
64
- console.log("Target mode:", targetMode);
65
- console.log("Platform:", platform);
66
- console.log("HMR active:", hmrActive);
67
- console.log("--------------");
68
- }
69
- const flavor = determineProjectFlavor();
70
- console.log(`Building for ${flavor}.`);
71
- // Suppress extremely noisy sourcemap warnings for third-party packages
72
- // These occur because published packages often omit original TS sources referenced by their .map files.
73
- // They have no runtime effect but clutter the console in dev.
74
- const baseLogger = createLogger(undefined, { allowClearScreen: true });
75
- const filteredLogger = {
76
- ...baseLogger,
77
- warn(message, options) {
78
- const msg = message;
79
- if (msg.startsWith("Sourcemap for ") &&
80
- msg.includes("missing source files")) {
81
- // Swallow this specific noisy warning
82
- return;
83
- }
84
- return baseLogger.warn(message, options);
85
- },
86
- warnOnce(message) {
87
- const msg = message;
88
- if (msg.startsWith("Sourcemap for ") &&
89
- msg.includes("missing source files")) {
90
- return;
91
- }
92
- return baseLogger.warnOnce(message);
93
- },
94
- };
95
- // Create TypeScript aliases with platform support
96
- const tsConfigData = getTsConfigData(verboseLogs, platform);
97
- // Common resolve configuration for both main and worker builds
98
- // Build platform-aware extension preference order and exclude the opposite platform
99
- const platformExtensions = (() => {
100
- const base = [".tsx", ".jsx", ".ts", ".js"];
101
- const exts = [];
102
- if (platform === "android") {
103
- exts.push(".android.tsx", ".tsx", ".android.jsx", ".jsx", ".android.ts", ".ts", ".android.js", ".js");
104
- }
105
- else if (platform === "ios" || platform === "visionos") {
106
- // Treat visionOS like iOS for file resolution
107
- exts.push(".ios.tsx", ".tsx", ".ios.jsx", ".jsx", ".ios.ts", ".ts", ".ios.js", ".js");
108
- }
109
- else {
110
- // Fallback: no platform-specific preference
111
- exts.push(...base);
112
- }
113
- // Always allow these last
114
- exts.push(".mjs", ".json");
115
- return exts;
116
- })();
117
- const resolveConfig = {
118
- // ensures Vite prefers ESM entry‑points
119
- mainFields: ["module", "main"],
120
- // Make sure ESM conditions win during resolution
121
- conditions: ["module", "import", "browser", "default"],
122
- // use this with merge config instead or could list common dedupes in base here altogether
123
- dedupe: ["@nativescript/core", "nativescript-vue", "vue"],
124
- // Alias "@" and "~" to your src directory for cleaner imports
125
- alias: [
126
- // Provide a shim for node:module to avoid runtime crashes in NS
127
- {
128
- find: /^node:module$/,
129
- replacement: path.resolve(path.dirname(new URL(import.meta.url).pathname), "../shims/node-module.js"),
130
- },
131
- // Ensure set-value resolves to an absolute shim to avoid alias warnings and duplication
132
- [
133
- {
134
- find: /^set-value$/,
135
- replacement: require.resolve("@nativescript/vite/dist/shims/set-value.js"),
136
- },
137
- ],
138
- ...aliasCssTree,
139
- // 1) Catch exactly `~/package.json` → virtual module (MUST be first!)
140
- { find: /^~\/package\.json$/, replacement: "~/package.json" },
141
- // TypeScript path aliases from tsconfig.json
142
- ...tsConfigData.aliases,
143
- // Generic platform resolution for any npm package
144
- packagePlatformAliases(tsConfigData, platform, verboseLogs),
145
- // 2) Catch everything else under "~/" → your src/
146
- { find: /^~\/(.*)$/, replacement: path.resolve(projectRoot, "src/$1") },
147
- // optional: "@" → src/
148
- { find: "@", replacement: path.resolve(projectRoot, "src") },
149
- ],
150
- extensions: platformExtensions,
151
- preserveSymlinks: true,
152
- };
153
- // Common define configuration for both main and worker builds
154
- const defineConfig = getGlobalDefines(platform, targetMode);
155
- // Default static copy: copy/merge assets and fonts when present
156
- const assetsSrcDir = path.resolve(projectRoot, "src/assets");
157
- const assetsAppDir = path.resolve(projectRoot, "app/assets");
158
- const fontsSrcDir = path.resolve(projectRoot, "src/fonts");
159
- const fontsAppDir = path.resolve(projectRoot, "app/fonts");
160
- const staticCopyTargets = [];
161
- if (existsSync(assetsSrcDir)) {
162
- staticCopyTargets.push({ src: `${assetsSrcDir}/**/*`, dest: "assets" });
163
- }
164
- else if (existsSync(assetsAppDir)) {
165
- staticCopyTargets.push({ src: `${assetsAppDir}/**/*`, dest: "assets" });
166
- }
167
- if (existsSync(fontsSrcDir)) {
168
- staticCopyTargets.push({ src: `${fontsSrcDir}/**/*`, dest: "fonts" });
169
- }
170
- else if (existsSync(fontsAppDir)) {
171
- staticCopyTargets.push({ src: `${fontsAppDir}/**/*`, dest: "fonts" });
172
- }
173
- let baseViteConfig = {
174
- // Suppress logs during HMR development if desired:
175
- // ...(hmrActive ? { logLevel: "warn" as const } : {}),
176
- // Filter out noisy sourcemap warnings from dependencies while keeping other warnings intact
177
- customLogger: filteredLogger,
178
- resolve: resolveConfig,
179
- // Propagate a single verbose flag into the runtime so device-side code can gate logs consistently
180
- define: {
181
- ...defineConfig,
182
- __NS_ENV_VERBOSE__: verboseLogs,
183
- },
184
- // Vite's built-in solution for CommonJS/ESM compatibility issues
185
- optimizeDeps: {
186
- // Force pre-bundling of problematic CommonJS packages
187
- include: [],
188
- // Handle Node.js built-ins and other edge cases
189
- esbuildOptions: {
190
- // Pass the same conditions to ESBuild for css-tree compatibility
191
- conditions: ["module", "import", "browser", "default"],
192
- // Define globals for Node.js built-ins if needed
193
- define: {
194
- global: "globalThis",
195
- "process.env.NODE_ENV": JSON.stringify(debug ? "development" : "production"),
196
- },
197
- },
198
- // Avoid pre-bundling NativeScript core to prevent esbuild from stripping side-effectful modules
199
- exclude: [
200
- "@nativescript/core",
201
- "@nativescript/core/ui/frame",
202
- "@nativescript/core/ui/frame/activity",
203
- // Do not prebundle NS-only websocket polyfill or the set-value shim
204
- "@valor/nativescript-websockets",
205
- "set-value",
206
- // Keep React-native related out unless explicitly needed per flavor
207
- "react",
208
- "react-reconciler",
209
- "react-nativescript",
210
- ],
211
- },
212
- esbuild: {
213
- define: {
214
- "process.env.NODE_ENV": JSON.stringify(debug ? "development" : "production"),
215
- },
216
- },
217
- plugins: [
218
- // Ensure Rollup phase replaces in node_modules too
219
- // Important for various vendor handling
220
- replace({
221
- "process.env.NODE_ENV": JSON.stringify(debug ? "development" : "production"),
222
- preventAssignment: true,
223
- }),
224
- // Ensure explicit keep markers are honored
225
- preserveImportsPlugin(),
226
- // Vue HMR plugins for development mode
227
- ...(hmrActive ? getHMRPlugins(platform, flavor, verboseLogs) : []),
228
- // TODO: make flavor plugins dynamic
229
- // ...flavorPlugins,
230
- ...commonjsPlugins,
231
- // Platform-specific package resolver - MUST come before commonjs plugin
232
- nativescriptPackageResolver(platform),
233
- // Simplified CommonJS handling - let Vite's optimizeDeps do the heavy lifting
234
- commonjs({
235
- include: [/node_modules/],
236
- // Force specific problematic modules to be treated as CommonJS
237
- requireReturnsDefault: "auto",
238
- defaultIsModuleExports: "auto",
239
- transformMixedEsModules: true,
240
- // Ignore optional dependencies that are meant to fail gracefully
241
- ignore: ["@nativescript/android", "@nativescript/ios"],
242
- }),
243
- nsConfigAsJsonPlugin(),
244
- NativeScriptPlugin({ platform }),
245
- // Ensure globals and Android activity are included early via virtual entry
246
- mainEntryPlugin(platform, verboseLogs, hmrActive),
247
- dynamicImportPlugin(),
248
- // Transform Vite worker URLs to NativeScript format AFTER bundling
249
- workerUrlPlugin(),
250
- // Copy static assets and fonts when present in project src/
251
- ...((staticCopyTargets == null ? void 0 : staticCopyTargets.length)
252
- ? [
253
- viteStaticCopy({
254
- targets: staticCopyTargets,
255
- watch: { reloadPageOnChange: true },
256
- }),
257
- ]
258
- : []),
259
- // NativeScript CLI integration
260
- cliPlugin(distOutputFolder, isDevMode, verboseLogs, hmrActive),
261
- ],
262
- css: {
263
- postcss: "./postcss.config.js",
264
- },
265
- // Development server configuration for HMR
266
- server: isDevMode
267
- ? {
268
- // Expose dev server to local network so simulator or device can connect
269
- host: process.env.NS_HMR_HOST ||
270
- (platform === "android" ? "0.0.0.0" : "localhost"),
271
- // Use a stable port so the device URL remains correct
272
- port: 5173,
273
- strictPort: true,
274
- https: useHttps
275
- ? {
276
- // Optional: allow self-signed certs via env paths
277
- key: process.env.NS_HTTPS_KEY &&
278
- readFileSync(process.env.NS_HTTPS_KEY),
279
- cert: process.env.NS_HTTPS_CERT &&
280
- readFileSync(process.env.NS_HTTPS_CERT),
281
- }
282
- : undefined,
283
- // Keep HMR on the primary server port (Vite browser client stays on /vite-hmr)
284
- hmr: {
285
- protocol: useHttps ? "wss" : "ws",
286
- path: "/vite-hmr",
287
- },
288
- cors: true,
289
- }
290
- : {},
291
- // Configure worker builds to bundle everything into standalone workers
292
- worker: {
293
- format: "es",
294
- plugins: () => getWorkerPlugins(platform),
295
- rollupOptions: {
296
- // Don't externalize anything - bundle everything into the worker
297
- external: [],
298
- output: {
299
- // Inline all dynamic imports to create standalone bundle
300
- inlineDynamicImports: true,
301
- },
302
- },
303
- },
304
- build: {
305
- // Ensure Vite and plugins (like vite-plugin-static-copy) use the same output directory
306
- outDir: path.resolve(projectRoot, distOutputFolder),
307
- target: "esnext",
308
- minify: !debug,
309
- // Generate source maps for debugging
310
- // External sourcemaps so DevTools loads small .mjs files and fetches maps on demand
311
- sourcemap: debug,
312
- // Disable module preloading to avoid browser APIs
313
- modulePreload: false,
314
- // Under HMR, avoid rebuilds on src/** changes — device consumes updates via /ns-hmr
315
- ...(hmrActive && {
316
- watch: {
317
- exclude: ["src/**"],
318
- },
319
- }),
320
- // Optimize for development speed
321
- ...(isDevMode && {
322
- // Faster builds in development
323
- reportCompressedSize: false,
324
- chunkSizeWarningLimit: 2000,
325
- }),
326
- commonjsOptions: {
327
- include: [/node_modules/],
328
- },
329
- rollupOptions: {
330
- treeshake: {
331
- // Preserve side effects for NativeScript core so classes/functions
332
- // aren't tree-shaken out of vendor.mjs.
333
- moduleSideEffects: (id) => /node_modules[\\\/]\@nativescript[\\\/]core[\\\/]/.test(id) || null,
334
- },
335
- input: "virtual:entry-with-polyfills",
336
- output: {
337
- format: "es", // Emit ES modules (.mjs)
338
- entryFileNames: "bundle.mjs",
339
- // Point source map URLs to absolute file:// paths on the host so
340
- // Chrome DevTools can fetch them even though the running code comes
341
- // from file:///app on the simulator/device.
342
- sourcemapBaseUrl: pathToFileURL(path.resolve(projectRoot, distOutputFolder)).toString() + "/",
343
- chunkFileNames: (chunk) => {
344
- if (chunk.name === "vendor")
345
- return "vendor.mjs";
346
- // Place worker files at root level, not in assets/
347
- if (chunk.name && chunk.name.includes("worker")) {
348
- return "[name]-[hash].js";
349
- }
350
- return "[name]-[hash].mjs";
351
- },
352
- assetFileNames: "assets/[name][extname]",
353
- // Create single vendor chunk - no separate globals chunk to avoid circular deps
354
- manualChunks(id) {
355
- if (id.includes("node_modules")) {
356
- // Keep common dependencies in the main bundle
357
- // Very Important: keep Angular, NS Angular and core in main bundle to avoid issues with DI
358
- // All flavors can do same if encounter ordering issues
359
- if (id.includes("@angular/") ||
360
- id.includes("@nativescript/angular") ||
361
- id.includes("@nativescript/core")) {
362
- return undefined; // Keep in main bundle
363
- }
364
- return "vendor";
365
- }
366
- },
367
- },
368
- // When HMR is active, prevent Vite's build watcher from reacting to src/** changes.
369
- // The device will get updates via socket /ns-hmr instead.
370
- ...(hmrActive
371
- ? {
372
- watch: {
373
- exclude: ["src/**"],
374
- },
375
- }
376
- : {}),
377
- },
378
- },
379
- };
380
- if (externalConfigMerges?.length) {
381
- externalConfigMerges.forEach((config) => {
382
- baseViteConfig = mergeConfig(baseViteConfig, config);
383
- });
384
- }
385
- return baseViteConfig;
386
- };
@@ -1,45 +0,0 @@
1
- import vue from "@vitejs/plugin-vue";
2
- import vueJsx from "@vitejs/plugin-vue-jsx";
3
- import path from "path";
4
- import alias from "@rollup/plugin-alias";
5
- import { fileURLToPath } from "node:url";
6
- import { dirname, resolve } from "node:path";
7
- import { mergeConfig } from "vite";
8
- import { baseConfig } from "./base.js";
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = dirname(__filename);
11
- const plugins = [
12
- {
13
- ...alias({
14
- entries: {
15
- vue: "nativescript-vue",
16
- "set-value": resolve(__dirname, "../shims/set-value.js"),
17
- },
18
- }),
19
- enforce: "pre",
20
- },
21
- // Enable Vue Single File Component support
22
- vue({
23
- // NativeScript projects often use <script setup lang="ts">
24
- script: {
25
- defineModel: true,
26
- propsDestructure: true,
27
- },
28
- // Keep template compilation basic; transform asset URLs is not needed for NS
29
- template: {
30
- transformAssetUrls: false,
31
- compilerOptions: {
32
- // Only treat real web custom elements (hyphenated) as custom.
33
- // DO NOT match PascalCase NativeScript tags.
34
- isCustomElement: (tag) => tag.includes("-"),
35
- },
36
- },
37
- }),
38
- // Optional: allow JSX/TSX in Vue components if used
39
- vueJsx(),
40
- ];
41
- export const vueConfig = ({ mode }) => {
42
- return mergeConfig(baseConfig({ mode }), {
43
- plugins,
44
- });
45
- };
@@ -1,21 +0,0 @@
1
- import path from "path";
2
- import { __dirname } from './project.js';
3
- export const aliasCssTree = [
4
- // Node.js built-ins and mdn-data polyfills for css-tree
5
- {
6
- find: "module",
7
- replacement: path.resolve(__dirname, "../polyfills/module.js"),
8
- },
9
- {
10
- find: "mdn-data/css/properties.json",
11
- replacement: path.resolve(__dirname, "../polyfills/mdn-data-properties.js"),
12
- },
13
- {
14
- find: "mdn-data/css/syntaxes.json",
15
- replacement: path.resolve(__dirname, "../polyfills/mdn-data-syntaxes.js"),
16
- },
17
- {
18
- find: "mdn-data/css/at-rules.json",
19
- replacement: path.resolve(__dirname, "../polyfills/mdn-data-at-rules.js"),
20
- },
21
- ];
@@ -1,40 +0,0 @@
1
- // import { defaultConfigs } from '..';
2
- import { getAllDependencies } from "./utils.js";
3
- /**
4
- * Utility to determine the project flavor based on installed dependencies
5
- * (vue, angular, react, svelete, typescript, javascript...)
6
- */
7
- export function determineProjectFlavor() {
8
- const dependencies = getAllDependencies();
9
- if (dependencies.includes("nativescript-vue")) {
10
- return "vue";
11
- }
12
- if (dependencies.includes("@nativescript/angular")) {
13
- return "angular";
14
- }
15
- if (dependencies.includes("react-nativescript")) {
16
- return "react";
17
- }
18
- if (dependencies.includes("@nativescript-community/solid-js") ||
19
- dependencies.includes("solid-js")) {
20
- return "solid";
21
- }
22
- if (dependencies.includes("svelte-native") ||
23
- dependencies.includes("@nativescript-community/svelte-native")) {
24
- return "svelte";
25
- }
26
- // the order is important - angular, react, and svelte also include these deps
27
- // but should return prior to this condition!
28
- if (dependencies.includes("@nativescript/core") &&
29
- dependencies.includes("typescript")) {
30
- return "typescript";
31
- }
32
- if (dependencies.includes("@nativescript/core")) {
33
- return "javascript";
34
- }
35
- console.info(`
36
- Could not determine project flavor.
37
- Please use webpack.useConfig('<flavor>') to explicitly set the base config.
38
- `);
39
- return false;
40
- }
@@ -1,20 +0,0 @@
1
- export function getGlobalDefines(platform, targetMode) {
2
- return {
3
- // Define platform flags for runtime checks
4
- __ANDROID__: JSON.stringify(platform === "android"),
5
- __IOS__: JSON.stringify(platform === "ios"),
6
- __VISIONOS__: JSON.stringify(platform === "visionos"),
7
- __APPLE__: JSON.stringify(platform === "ios" || platform === "visionos"),
8
- __DEV__: JSON.stringify(targetMode === "development"),
9
- __COMMONJS__: false,
10
- __NS_WEBPACK__: true,
11
- __NS_ENV_VERBOSE__: !!process.env.verbose,
12
- __CSS_PARSER__: JSON.stringify("css-tree"),
13
- __UI_USE_XML_PARSER__: true,
14
- __UI_USE_EXTERNAL_RENDERER__: false,
15
- // various ecosystems use this global (react for example)
16
- __TEST__: false,
17
- // Critical for various integrations (e.g. Vue only includes hmr runtime on this conditions)
18
- "process.env.NODE_ENV": JSON.stringify(targetMode === "development" ? "development" : "production"),
19
- };
20
- }
@@ -1 +0,0 @@
1
- export declare function embedMainEntryHMRForFlavor(flavor: string): string;
@@ -1,18 +0,0 @@
1
- export function embedMainEntryHMRForFlavor(flavor) {
2
- let imports = "";
3
- switch (flavor) {
4
- case "vue":
5
- // Load HMR client for WebSocket connection to Vite dev server
6
- imports += "import 'virtual:hmr-vue';\n";
7
- imports +=
8
- "console.info('@nativescript/vite HMR Vue client loaded.');\n";
9
- break;
10
- case "react":
11
- break;
12
- case "angular":
13
- break;
14
- case "solid":
15
- break;
16
- }
17
- return imports;
18
- }
@@ -1,5 +0,0 @@
1
- export declare function mainEntryPlugin(platform: "ios" | "android" | "visionos", verboseLogs: boolean, hmrActive: boolean): {
2
- name: string;
3
- resolveId(id: string): string;
4
- load(id: string): string;
5
- };
@@ -1,82 +0,0 @@
1
- import { getPackageJson, getProjectFilePath, getProjectRootPath, } from "./project.js";
2
- import fs from "fs";
3
- import path from "path";
4
- import { determineProjectFlavor } from "./flavor.js";
5
- import { embedMainEntryHMRForFlavor } from "./main-entry-hmr-includes.js";
6
- const projectRoot = getProjectRootPath();
7
- // main entry
8
- const packageJson = getPackageJson();
9
- const mainEntry = getProjectFilePath(packageJson.main);
10
- const flavor = determineProjectFlavor();
11
- // Check if polyfills file exists
12
- const polyfillsPath = getProjectFilePath("src/polyfills.ts");
13
- const polyfillsExists = fs.existsSync(polyfillsPath);
14
- const VIRTUAL_ID = "virtual:entry-with-polyfills";
15
- const RESOLVED = "\0" + VIRTUAL_ID;
16
- export function mainEntryPlugin(platform, verboseLogs, hmrActive) {
17
- return {
18
- name: "main-entry",
19
- resolveId(id) {
20
- if (id === VIRTUAL_ID)
21
- return RESOLVED;
22
- return null;
23
- },
24
- load(id) {
25
- if (id !== RESOLVED)
26
- return null;
27
- let imports = "";
28
- // Align with webpack entry order: core globals and bundle entry points first
29
- imports += "import '@nativescript/core/globals/index';\n";
30
- // explicit extension helps some bundlers to retain side effects
31
- imports += "import '@nativescript/core/bundle-entry-points';\n";
32
- // Ensure Android app components are included
33
- if (platform === "android") {
34
- // Import explicit Android variants with extension to avoid resolution ambiguity
35
- imports +=
36
- "import * as __ns_android_frame from '@nativescript/core/ui/frame/index.android.js?ns-keep';\n";
37
- imports +=
38
- "import * as __ns_android_activity from '@nativescript/core/ui/frame/activity.android.js?ns-keep';\n";
39
- // Reference bindings to keep the modules in the graph even if they only have side effects
40
- imports += "void __ns_android_frame; void __ns_android_activity;\n";
41
- }
42
- if (polyfillsExists) {
43
- imports += `import '${polyfillsPath}';\n`;
44
- // Ensure path is emitted as a proper JS string literal
45
- imports += `if (__NS_ENV_VERBOSE__) console.info('[ns-entry] polyfills imported from', ${JSON.stringify(polyfillsPath)});\n`;
46
- }
47
- else {
48
- imports += "if (__NS_ENV_VERBOSE__) console.info('[ns-entry] no polyfills file found');\n";
49
- }
50
- if (hmrActive) {
51
- // Ensure WebSocket polyfill is loaded early for device runtime
52
- imports += "import '@valor/nativescript-websockets';\n";
53
- imports += "if (__NS_ENV_VERBOSE__) console.info('[ns-entry] websockets polyfill imported');\n";
54
- }
55
- // Import CSS and apply via Application.addCss before main entry
56
- const appCssPath = path.resolve(projectRoot, "src/app.css");
57
- if (fs.existsSync(appCssPath)) {
58
- imports += `
59
- // Import and apply global CSS before app bootstrap
60
- import appCssContent from './src/app.css?inline';
61
- import { Application } from '@nativescript/core';
62
- if (appCssContent) {
63
- try { Application.addCss(appCssContent); } catch (error) { console.error('Error applying CSS:', error); }
64
- }
65
- `;
66
- }
67
- // Import the main entry file
68
- imports += `if (__NS_ENV_VERBOSE__) console.info('[ns-entry] Importing main entry', '${mainEntry}');\n`;
69
- imports += `import '${mainEntry}';\n`;
70
- if (hmrActive) {
71
- // Start HMR client after app boots
72
- imports += embedMainEntryHMRForFlavor(flavor);
73
- }
74
- // Import inspector modules for debugging in development
75
- if (verboseLogs) {
76
- imports += "import '@nativescript/core/inspector_modules';\n";
77
- imports += "if (__NS_ENV_VERBOSE__) console.info('[ns-entry] inspector modules imported');\n";
78
- }
79
- return imports;
80
- },
81
- };
82
- }
@@ -1,4 +0,0 @@
1
- export declare function packagePlatformAliases(tsConfigData: any, platform: string, verboseLogs?: boolean): {
2
- find: RegExp;
3
- replacement: (id: any) => any;
4
- };
@@ -1,19 +0,0 @@
1
- // Marks modules imported with `?ns-keep` as side-effectful so Rollup won't tree-shake them.
2
- export function preserveImportsPlugin() {
3
- return {
4
- name: 'ns-preserve-imports',
5
- // run early so downstream plugins see the preserved flag
6
- enforce: 'pre',
7
- async transform(code, id) {
8
- if (id.includes('?ns-keep')) {
9
- return {
10
- code,
11
- map: null,
12
- // ensure side effects are preserved even if bindings are unused
13
- moduleSideEffects: true,
14
- };
15
- }
16
- return null;
17
- },
18
- };
19
- }
@@ -1,4 +0,0 @@
1
- import type { Plugin } from "vite";
2
- export default function NativeScriptPlugin(options: {
3
- platform: "ios" | "android" | "visionos";
4
- }): Plugin;
@@ -1,4 +0,0 @@
1
- export declare const getTsConfigData: (verboseLogs: boolean, platform: string) => {
2
- data: any;
3
- aliases: any[];
4
- };