vxrn 0.1.97 → 0.1.99

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 (184) hide show
  1. package/dist/cjs/exports/build.js.map +1 -1
  2. package/dist/cjs/exports/build.native.js.map +1 -1
  3. package/dist/cjs/exports/dev.js +1 -1
  4. package/dist/cjs/exports/dev.js.map +1 -1
  5. package/dist/cjs/exports/dev.native.js +4 -4
  6. package/dist/cjs/exports/dev.native.js.map +1 -1
  7. package/dist/cjs/index.js +1 -0
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/index.native.js +2 -0
  10. package/dist/cjs/index.native.js.map +1 -1
  11. package/dist/cjs/plugins/clientInjectPlugin.js +3 -3
  12. package/dist/cjs/plugins/clientInjectPlugin.js.map +1 -1
  13. package/dist/cjs/plugins/clientInjectPlugin.native.js +3 -3
  14. package/dist/cjs/plugins/clientInjectPlugin.native.js.map +2 -2
  15. package/dist/cjs/plugins/reactNativeCommonJsPlugin.js +116 -48
  16. package/dist/cjs/plugins/reactNativeCommonJsPlugin.js.map +1 -1
  17. package/dist/cjs/plugins/reactNativeCommonJsPlugin.native.js +208 -147
  18. package/dist/cjs/plugins/reactNativeCommonJsPlugin.native.js.map +2 -2
  19. package/dist/cjs/plugins/reactNativeHMRPlugin.js +2 -0
  20. package/dist/cjs/plugins/reactNativeHMRPlugin.js.map +1 -1
  21. package/dist/cjs/plugins/reactNativeHMRPlugin.native.js +111 -107
  22. package/dist/cjs/plugins/reactNativeHMRPlugin.native.js.map +1 -1
  23. package/dist/cjs/{exports/isWithin.js → utils/environmentUtils.js} +19 -9
  24. package/dist/cjs/utils/environmentUtils.js.map +6 -0
  25. package/dist/cjs/utils/environmentUtils.native.js +43 -0
  26. package/dist/cjs/utils/environmentUtils.native.js.map +6 -0
  27. package/dist/cjs/utils/getOptimizeDeps.js +3 -2
  28. package/dist/cjs/utils/getOptimizeDeps.js.map +1 -1
  29. package/dist/cjs/utils/getOptimizeDeps.native.js +3 -2
  30. package/dist/cjs/utils/getOptimizeDeps.native.js.map +1 -1
  31. package/dist/cjs/utils/getReactNativeBundle.js +1 -1
  32. package/dist/cjs/utils/getReactNativeBundle.js.map +1 -1
  33. package/dist/cjs/utils/getReactNativeBundle.native.js +8 -3
  34. package/dist/cjs/utils/getReactNativeBundle.native.js.map +2 -2
  35. package/dist/esm/exports/build.js.map +1 -1
  36. package/dist/esm/exports/build.native.js.map +1 -1
  37. package/dist/esm/exports/dev.js +1 -1
  38. package/dist/esm/exports/dev.js.map +1 -1
  39. package/dist/esm/exports/dev.mjs +1 -1
  40. package/dist/esm/exports/dev.native.js +4 -4
  41. package/dist/esm/exports/dev.native.js.map +1 -1
  42. package/dist/esm/index.js +1 -0
  43. package/dist/esm/index.js.map +1 -1
  44. package/dist/esm/index.mjs +1 -0
  45. package/dist/esm/index.native.js +1 -0
  46. package/dist/esm/index.native.js.map +1 -1
  47. package/dist/esm/plugins/clientInjectPlugin.js +3 -2
  48. package/dist/esm/plugins/clientInjectPlugin.js.map +1 -1
  49. package/dist/esm/plugins/clientInjectPlugin.mjs +3 -2
  50. package/dist/esm/plugins/clientInjectPlugin.native.js +3 -2
  51. package/dist/esm/plugins/clientInjectPlugin.native.js.map +2 -2
  52. package/dist/esm/plugins/reactNativeCommonJsPlugin.js +117 -48
  53. package/dist/esm/plugins/reactNativeCommonJsPlugin.js.map +1 -1
  54. package/dist/esm/plugins/reactNativeCommonJsPlugin.mjs +107 -41
  55. package/dist/esm/plugins/reactNativeCommonJsPlugin.native.js +209 -147
  56. package/dist/esm/plugins/reactNativeCommonJsPlugin.native.js.map +2 -2
  57. package/dist/esm/plugins/reactNativeHMRPlugin.js +2 -0
  58. package/dist/esm/plugins/reactNativeHMRPlugin.js.map +1 -1
  59. package/dist/esm/plugins/reactNativeHMRPlugin.mjs +2 -0
  60. package/dist/esm/plugins/reactNativeHMRPlugin.native.js +111 -107
  61. package/dist/esm/plugins/reactNativeHMRPlugin.native.js.map +1 -1
  62. package/dist/esm/utils/environmentUtils.js +19 -0
  63. package/dist/esm/utils/environmentUtils.js.map +6 -0
  64. package/dist/esm/utils/environmentUtils.mjs +13 -0
  65. package/dist/esm/utils/environmentUtils.native.js +19 -0
  66. package/dist/esm/utils/environmentUtils.native.js.map +6 -0
  67. package/dist/esm/utils/getOptimizeDeps.js +3 -2
  68. package/dist/esm/utils/getOptimizeDeps.js.map +1 -1
  69. package/dist/esm/utils/getOptimizeDeps.mjs +1 -1
  70. package/dist/esm/utils/getOptimizeDeps.native.js +3 -2
  71. package/dist/esm/utils/getOptimizeDeps.native.js.map +1 -1
  72. package/dist/esm/utils/getReactNativeBundle.js +6 -2
  73. package/dist/esm/utils/getReactNativeBundle.js.map +1 -1
  74. package/dist/esm/utils/getReactNativeBundle.mjs +3 -2
  75. package/dist/esm/utils/getReactNativeBundle.native.js +9 -4
  76. package/dist/esm/utils/getReactNativeBundle.native.js.map +2 -2
  77. package/package.json +5 -5
  78. package/src/exports/build.ts +0 -1
  79. package/src/exports/dev.ts +4 -2
  80. package/src/index.ts +2 -0
  81. package/src/plugins/clientInjectPlugin.ts +6 -3
  82. package/src/plugins/reactNativeCommonJsPlugin.ts +159 -146
  83. package/src/plugins/reactNativeHMRPlugin.ts +4 -1
  84. package/src/utils/environmentUtils.ts +17 -0
  85. package/src/utils/getOptimizeDeps.ts +3 -2
  86. package/src/utils/getReactNativeBundle.ts +11 -2
  87. package/types/index.d.ts +1 -0
  88. package/types/plugins/reactNativeCommonJsPlugin.d.ts +1 -1
  89. package/types/plugins/reactNativeHMRPlugin.d.ts +1 -5
  90. package/types/utils/environmentUtils.d.ts +6 -0
  91. package/dist/cjs/exports/bindKeypressInput.js +0 -58
  92. package/dist/cjs/exports/bindKeypressInput.js.map +0 -6
  93. package/dist/cjs/exports/bindKeypressInput.native.js +0 -63
  94. package/dist/cjs/exports/bindKeypressInput.native.js.map +0 -6
  95. package/dist/cjs/exports/coerceToArray.js +0 -23
  96. package/dist/cjs/exports/coerceToArray.js.map +0 -6
  97. package/dist/cjs/exports/connectedNativeClients.js +0 -21
  98. package/dist/cjs/exports/connectedNativeClients.js.map +0 -6
  99. package/dist/cjs/exports/empty.js +0 -1
  100. package/dist/cjs/exports/empty.js.map +0 -6
  101. package/dist/cjs/exports/empty.native.js +0 -2
  102. package/dist/cjs/exports/empty.native.js.map +0 -6
  103. package/dist/cjs/exports/entryRoot.js +0 -69
  104. package/dist/cjs/exports/entryRoot.js.map +0 -6
  105. package/dist/cjs/exports/getIndexJsonResponse.js +0 -71
  106. package/dist/cjs/exports/getIndexJsonResponse.js.map +0 -6
  107. package/dist/cjs/exports/getIndexJsonResponse.native.js +0 -99
  108. package/dist/cjs/exports/getIndexJsonResponse.native.js.map +0 -6
  109. package/dist/cjs/exports/getReactNativeBundle.js +0 -160
  110. package/dist/cjs/exports/getReactNativeBundle.js.map +0 -6
  111. package/dist/cjs/exports/getViteServerConfig.js +0 -77
  112. package/dist/cjs/exports/getViteServerConfig.js.map +0 -6
  113. package/dist/cjs/exports/getViteServerConfig.native.js +0 -253
  114. package/dist/cjs/exports/getViteServerConfig.native.js.map +0 -6
  115. package/dist/cjs/exports/hotUpdateCache.js +0 -21
  116. package/dist/cjs/exports/hotUpdateCache.js.map +0 -6
  117. package/dist/cjs/exports/isBuildingNativeBundle.js +0 -21
  118. package/dist/cjs/exports/isBuildingNativeBundle.js.map +0 -6
  119. package/dist/cjs/exports/isWithin.js.map +0 -6
  120. package/dist/cjs/exports/reactNativeHMRPlugin.js +0 -69
  121. package/dist/cjs/exports/reactNativeHMRPlugin.js.map +0 -6
  122. package/dist/cjs/exports/swapPrebuiltReactModules.js +0 -100
  123. package/dist/cjs/exports/swapPrebuiltReactModules.js.map +0 -6
  124. package/dist/cjs/exports/uniq.js +0 -23
  125. package/dist/cjs/exports/uniq.js.map +0 -6
  126. package/dist/cjs/utils/getHtml.js +0 -49
  127. package/dist/cjs/utils/getHtml.js.map +0 -6
  128. package/dist/cjs/utils/getHtml.native.js +0 -76
  129. package/dist/cjs/utils/getHtml.native.js.map +0 -6
  130. package/dist/esm/exports/bindKeypressInput.js +0 -34
  131. package/dist/esm/exports/bindKeypressInput.js.map +0 -6
  132. package/dist/esm/exports/bindKeypressInput.mjs +0 -31
  133. package/dist/esm/exports/bindKeypressInput.native.js +0 -34
  134. package/dist/esm/exports/bindKeypressInput.native.js.map +0 -6
  135. package/dist/esm/exports/coerceToArray.js +0 -7
  136. package/dist/esm/exports/coerceToArray.js.map +0 -6
  137. package/dist/esm/exports/coerceToArray.mjs +0 -4
  138. package/dist/esm/exports/connectedNativeClients.js +0 -5
  139. package/dist/esm/exports/connectedNativeClients.js.map +0 -6
  140. package/dist/esm/exports/connectedNativeClients.mjs +0 -2
  141. package/dist/esm/exports/empty.js +0 -1
  142. package/dist/esm/exports/empty.js.map +0 -6
  143. package/dist/esm/exports/empty.mjs +0 -0
  144. package/dist/esm/exports/empty.native.js +0 -1
  145. package/dist/esm/exports/empty.native.js.map +0 -6
  146. package/dist/esm/exports/entryRoot.js +0 -58
  147. package/dist/esm/exports/entryRoot.js.map +0 -6
  148. package/dist/esm/exports/entryRoot.mjs +0 -62
  149. package/dist/esm/exports/getIndexJsonResponse.js +0 -55
  150. package/dist/esm/exports/getIndexJsonResponse.js.map +0 -6
  151. package/dist/esm/exports/getIndexJsonResponse.mjs +0 -71
  152. package/dist/esm/exports/getIndexJsonResponse.native.js +0 -78
  153. package/dist/esm/exports/getIndexJsonResponse.native.js.map +0 -6
  154. package/dist/esm/exports/getReactNativeBundle.js +0 -146
  155. package/dist/esm/exports/getReactNativeBundle.js.map +0 -6
  156. package/dist/esm/exports/getReactNativeBundle.mjs +0 -136
  157. package/dist/esm/exports/getViteServerConfig.js +0 -64
  158. package/dist/esm/exports/getViteServerConfig.js.map +0 -6
  159. package/dist/esm/exports/getViteServerConfig.mjs +0 -44
  160. package/dist/esm/exports/getViteServerConfig.native.js +0 -235
  161. package/dist/esm/exports/getViteServerConfig.native.js.map +0 -6
  162. package/dist/esm/exports/hotUpdateCache.js +0 -5
  163. package/dist/esm/exports/hotUpdateCache.js.map +0 -6
  164. package/dist/esm/exports/hotUpdateCache.mjs +0 -2
  165. package/dist/esm/exports/isBuildingNativeBundle.js +0 -5
  166. package/dist/esm/exports/isBuildingNativeBundle.js.map +0 -6
  167. package/dist/esm/exports/isBuildingNativeBundle.mjs +0 -2
  168. package/dist/esm/exports/isWithin.js +0 -9
  169. package/dist/esm/exports/isWithin.js.map +0 -6
  170. package/dist/esm/exports/isWithin.mjs +0 -6
  171. package/dist/esm/exports/reactNativeHMRPlugin.js +0 -58
  172. package/dist/esm/exports/reactNativeHMRPlugin.js.map +0 -6
  173. package/dist/esm/exports/reactNativeHMRPlugin.mjs +0 -62
  174. package/dist/esm/exports/swapPrebuiltReactModules.js +0 -87
  175. package/dist/esm/exports/swapPrebuiltReactModules.js.map +0 -6
  176. package/dist/esm/exports/swapPrebuiltReactModules.mjs +0 -73
  177. package/dist/esm/exports/uniq.js +0 -7
  178. package/dist/esm/exports/uniq.js.map +0 -6
  179. package/dist/esm/exports/uniq.mjs +0 -4
  180. package/dist/esm/utils/getHtml.js +0 -33
  181. package/dist/esm/utils/getHtml.js.map +0 -6
  182. package/dist/esm/utils/getHtml.mjs +0 -23
  183. package/dist/esm/utils/getHtml.native.js +0 -55
  184. package/dist/esm/utils/getHtml.native.js.map +0 -6
@@ -1,6 +1,7 @@
1
1
  import path from 'node:path'
2
2
 
3
3
  import type { HmrOptions, Plugin, ResolvedConfig, UserConfig } from 'vite'
4
+ import { isNativeEnvironment } from '../utils/environmentUtils'
4
5
 
5
6
  const process_env_NODE_ENV_RE = /(\bglobal(This)?\.)?\bprocess\.env\.NODE_ENV\b/g
6
7
 
@@ -78,9 +79,11 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin {
78
79
  }
79
80
  },
80
81
 
81
- transform(code, id, options) {
82
- if (id.includes('vite-native-client/dist/esm/client.')) {
83
- return injectConfigValues(code)
82
+ transform(code, id) {
83
+ if (isNativeEnvironment(this.environment!)) {
84
+ if (id.includes('vite-native-client/dist/esm/client.')) {
85
+ return injectConfigValues(code)
86
+ }
84
87
  }
85
88
  },
86
89
  }
@@ -1,21 +1,25 @@
1
- import { dirname } from 'node:path'
2
1
  import { parse } from 'es-module-lexer'
3
- import type { OutputOptions } from 'rollup'
4
- import type { Plugin } from 'vite'
2
+ import { dirname } from 'node:path'
3
+ import { mergeConfig, type Plugin, type UserConfig } from 'vite'
5
4
  import { getVitePath } from '../utils/getVitePath'
6
5
 
7
- const extensions = [
8
- '.ios.js',
9
- '.native.js',
10
- '.native.ts',
11
- '.native.tsx',
12
- '.js',
13
- '.jsx',
14
- '.json',
15
- '.ts',
16
- '.tsx',
17
- '.mjs',
18
- ]
6
+ const getNativeExtensions = (platform: 'ios' | 'android') => {
7
+ return [
8
+ `.${platform}.tsx`,
9
+ `.${platform}.ts`,
10
+ `.${platform}.jsx`,
11
+ `.${platform}.js`,
12
+ '.native.js',
13
+ '.native.ts',
14
+ '.native.tsx',
15
+ '.tsx',
16
+ '.ts',
17
+ '.js',
18
+ '.jsx',
19
+ '.json',
20
+ '.mjs',
21
+ ]
22
+ }
19
23
 
20
24
  export function reactNativeCommonJsPlugin(options: {
21
25
  root: string
@@ -26,151 +30,160 @@ export function reactNativeCommonJsPlugin(options: {
26
30
  name: 'native',
27
31
  enforce: 'pre',
28
32
 
29
- config: async (config) => {
30
- config.define ||= {}
31
- config.define['process.env.REACT_NATIVE_SERVER_PUBLIC_PORT'] = JSON.stringify(
32
- `${options.port}`
33
- )
34
- config.define['process.env.REACT_NATIVE_PLATFORM'] = JSON.stringify(`ios`)
35
-
36
- if (!config.build) config.build = {}
37
-
38
- config.build.modulePreload = { polyfill: false }
39
- // Ensures that even very large assets are inlined in your JavaScript.
40
- config.build.assetsInlineLimit = 100000000
41
- // Avoid warnings about large chunks.
42
- config.build.chunkSizeWarningLimit = 100000000
43
- // Emit all CSS as a single file, which `vite-plugin-singlefile` can then inline.
44
- config.build.cssCodeSplit = false
45
- // Avoids the extra step of testing Brotli compression, which isn't really pertinent to a file served locally.
46
- config.build.reportCompressedSize = false
47
- // Subfolder bases are not supported, and shouldn't be needed because we're embedding everything.
48
- config.base = undefined
49
-
50
- config.resolve ??= {}
33
+ config: async () => {
34
+ const sharedNativeConfig = {
35
+ // Subfolder bases are not supported, and shouldn't be needed because we're embedding everything
36
+ base: undefined,
51
37
 
52
- config.resolve.extensions = extensions
53
-
54
- config.resolve.conditions = ['react-native', 'require', 'default', 'import']
55
-
56
- config.optimizeDeps ??= {}
57
-
58
- config.optimizeDeps.noDiscovery = true
59
- config.optimizeDeps.include = undefined
38
+ define: {
39
+ 'process.env.REACT_NATIVE_SERVER_PUBLIC_PORT': JSON.stringify(`${options.port}`),
40
+ },
60
41
 
61
- config.optimizeDeps.esbuildOptions ??= {}
62
- config.optimizeDeps.esbuildOptions.resolveExtensions = extensions
42
+ build: {
43
+ modulePreload: {
44
+ polyfill: false,
45
+ },
46
+ // Ensures that even very large assets are inlined in your JavaScript.
47
+ assetsInlineLimit: 100000000,
48
+ // Avoid warnings about large chunks
49
+ chunkSizeWarningLimit: 100000000,
50
+ // Emit all CSS as a single file, which `vite-plugin-singlefile` can then inline
51
+ cssCodeSplit: false,
52
+ // Avoids the extra step of testing Brotli compression, which isn't really pertinent to a file served locally
53
+ reportCompressedSize: false,
54
+
55
+ rollupOptions: {
56
+ output: {
57
+ preserveModules: true,
58
+ manualChunks: undefined,
59
+ // Ensure that as many resources as possible are inlined.
60
+ // inlineDynamicImports: true,
61
+ // this fixes some warnings but breaks import { default as config }
62
+ exports: 'named',
63
+ // ensures we have clean names for our require paths
64
+ entryFileNames: () => `[name].js`,
65
+ },
63
66
 
64
- config.optimizeDeps.esbuildOptions.plugins ??= []
67
+ plugins: [
68
+ {
69
+ name: `force-export-all`,
70
+
71
+ async transform(code, id) {
72
+ // if (!id.includes('/node_modules/')) {
73
+ // return
74
+ // }
75
+
76
+ try {
77
+ const [imports, exports] = parse(code)
78
+
79
+ let forceExports = ''
80
+
81
+ // note that es-module-lexer parses export * from as an import (twice) for some reason
82
+ let counts = {}
83
+ for (const imp of imports) {
84
+ if (imp.n && imp.n[0] !== '.') {
85
+ counts[imp.n] ||= 0
86
+ counts[imp.n]++
87
+ if (counts[imp.n] == 2) {
88
+ // star export
89
+ const path = await getVitePath(options.root, dirname(id), imp.n)
90
+ forceExports += `Object.assign(exports, require("${path}"));`
91
+ }
92
+ }
93
+ }
94
+
95
+ forceExports += exports
96
+ .map((e) => {
97
+ if (e.n === 'default') {
98
+ return ''
99
+ }
100
+ let out = ''
101
+ if (e.ln !== e.n) {
102
+ // forces the "as x" to be referenced so it gets exported
103
+ out += `__ignore = typeof ${e.n} === 'undefined' ? 0 : 0;`
104
+ }
105
+ out += `globalThis.____forceExport = ${e.ln}`
106
+ return out
107
+ })
108
+ .join(';')
109
+
110
+ return code + '\n' + forceExports
111
+ } catch (err) {
112
+ console.warn(`Error forcing exports, probably ok`, id)
113
+ }
114
+ },
115
+ },
116
+ ],
117
+ },
118
+ },
65
119
 
66
- config.optimizeDeps.esbuildOptions.loader ??= {}
67
- config.optimizeDeps.esbuildOptions.loader['.js'] = 'jsx'
120
+ optimizeDeps: {
121
+ noDiscovery: true,
122
+ include: undefined,
68
123
 
69
- config.optimizeDeps.esbuildOptions.plugins.push({
70
- name: 'react-native-assets',
71
- setup(build) {
72
- build.onResolve(
73
- {
74
- filter: /\.(png|jpg|gif|webp)$/,
124
+ esbuildOptions: {
125
+ loader: {
126
+ '.js': 'jsx',
75
127
  },
76
- async ({ path, namespace }) => {
77
- return {
78
- path: '',
79
- external: true,
80
- }
81
- }
82
- )
128
+ },
83
129
  },
84
- })
85
-
86
- config.build.rollupOptions ??= {}
87
-
88
- config.build.rollupOptions.output ??= {}
89
-
90
- config.build.rollupOptions.plugins ??= []
91
-
92
- if (!Array.isArray(config.build.rollupOptions.plugins)) {
93
- throw `x`
94
- }
130
+ } satisfies UserConfig
95
131
 
96
- if (options.mode === 'build') {
97
- config.plugins ||= []
132
+ // per-enviroment config:
98
133
 
99
- config.build.rollupOptions.plugins.push({
100
- name: `force-export-all`,
101
-
102
- async transform(code, id) {
103
- // if (!id.includes('/node_modules/')) {
104
- // return
105
- // }
106
-
107
- try {
108
- const [imports, exports] = parse(code)
109
-
110
- let forceExports = ''
111
-
112
- // note that es-module-lexer parses export * from as an import (twice) for some reason
113
- let counts = {}
114
- for (const imp of imports) {
115
- if (imp.n && imp.n[0] !== '.') {
116
- counts[imp.n] ||= 0
117
- counts[imp.n]++
118
- if (counts[imp.n] == 2) {
119
- // star export
120
- const path = await getVitePath(options.root, dirname(id), imp.n)
121
- forceExports += `Object.assign(exports, require("${path}"));`
122
- }
123
- }
124
- }
125
-
126
- forceExports += exports
127
- .map((e) => {
128
- if (e.n === 'default') {
129
- return ''
130
- }
131
- let out = ''
132
- if (e.ln !== e.n) {
133
- // forces the "as x" to be referenced so it gets exported
134
- out += `__ignore = typeof ${e.n} === 'undefined' ? 0 : 0;`
135
- }
136
- out += `globalThis.____forceExport = ${e.ln}`
137
- return out
138
- })
139
- .join(';')
140
-
141
- return code + '\n' + forceExports
142
- } catch (err) {
143
- console.warn(`Error forcing exports, probably ok`, id)
144
- }
145
- },
146
- })
147
- }
148
-
149
- if (process.env.DEBUG) {
150
- console.info('config..', config)
151
- }
134
+ return {
135
+ environments: {
136
+ ios: mergeConfig(sharedNativeConfig, {
137
+ define: {
138
+ 'process.env.REACT_NATIVE_PLATFORM': JSON.stringify(`ios`),
139
+ },
152
140
 
153
- const updateOutputOptions = (out: OutputOptions) => {
154
- out.preserveModules = true
141
+ resolve: {
142
+ extensions: getNativeExtensions('ios'),
143
+ },
155
144
 
156
- // this fixes some warnings but breaks import { default as config }
157
- // out.exports = 'named'
145
+ optimizeDeps: {
146
+ esbuildOptions: {
147
+ resolveExtensions: getNativeExtensions('ios'),
148
+
149
+ plugins: [
150
+ {
151
+ name: 'react-native-assets',
152
+ setup(build) {
153
+ build.onResolve(
154
+ {
155
+ filter: /\.(png|jpg|gif|webp)$/,
156
+ },
157
+ async ({ path, namespace }) => {
158
+ return {
159
+ path: '',
160
+ external: true,
161
+ }
162
+ }
163
+ )
164
+ },
165
+ },
166
+ ],
167
+ },
168
+ },
169
+ } satisfies UserConfig),
158
170
 
159
- out.entryFileNames = (chunkInfo) => {
160
- // ensures we have clean names for our require paths
161
- return '[name].js'
162
- }
163
- // Ensure that as many resources as possible are inlined.
164
- // out.inlineDynamicImports = true
171
+ android: mergeConfig(sharedNativeConfig, {
172
+ define: {
173
+ 'process.env.REACT_NATIVE_PLATFORM': JSON.stringify(`android`),
174
+ },
165
175
 
166
- // added by me (nate):
167
- out.manualChunks = undefined
168
- }
176
+ resolve: {
177
+ extensions: getNativeExtensions('android'),
178
+ },
169
179
 
170
- if (Array.isArray(config.build.rollupOptions.output)) {
171
- for (const o in config.build.rollupOptions.output) updateOutputOptions(o as OutputOptions)
172
- } else {
173
- updateOutputOptions(config.build.rollupOptions.output as OutputOptions)
180
+ optimizeDeps: {
181
+ esbuildOptions: {
182
+ resolveExtensions: getNativeExtensions('android'),
183
+ },
184
+ },
185
+ } satisfies UserConfig),
186
+ },
174
187
  }
175
188
  },
176
189
  }
@@ -6,11 +6,14 @@ import { entryRoot } from '../utils/getReactNativeBundle'
6
6
  import { getVitePath } from '../utils/getVitePath'
7
7
  import { hotUpdateCache } from '../utils/hotUpdateCache'
8
8
  import { isWithin } from '../utils/isWithin'
9
+ import type { Plugin } from 'vite'
9
10
 
10
11
  export function reactNativeHMRPlugin({ root }: VXRNConfigFilled) {
11
12
  return {
12
13
  name: 'client-transform',
13
14
 
15
+ // TODO see about moving to hotUpdate
16
+ // https://deploy-preview-16089--vite-docs-main.netlify.app/guide/api-vite-environment.html#the-hotupdate-hook
14
17
  async handleHotUpdate({ read, modules, file }) {
15
18
  try {
16
19
  if (!isWithin(root, file)) {
@@ -101,5 +104,5 @@ export function reactNativeHMRPlugin({ root }: VXRNConfigFilled) {
101
104
  console.error(`Error processing hmr update:`, err)
102
105
  }
103
106
  },
104
- }
107
+ } satisfies Plugin
105
108
  }
@@ -0,0 +1,17 @@
1
+ import type { Environment } from 'vite'
2
+
3
+ export function isWebEnvironment(environment: Environment) {
4
+ return environment.name === 'client' || environment.name === 'ssr'
5
+ }
6
+
7
+ export function isNativeEnvironment(environment: Environment) {
8
+ return environment.name === 'ios' || environment.name === 'android'
9
+ }
10
+
11
+ export function isIOSEnvironment(environment: Environment) {
12
+ return environment.name === 'ios'
13
+ }
14
+
15
+ export function isAndroidEnvironment(environment: Environment) {
16
+ return environment.name === 'android'
17
+ }
@@ -42,6 +42,9 @@ export function getOptimizeDeps(mode: 'build' | 'serve') {
42
42
  '@react-navigation/elements',
43
43
  '@react-navigation/bottom-tabs',
44
44
  '@react-navigation/native-stack',
45
+ 'vxs',
46
+ 'vxs/server-render',
47
+ 'vxs/headers',
45
48
  'requires-port',
46
49
  'querystringify',
47
50
  'compare-versions',
@@ -61,8 +64,6 @@ export function getOptimizeDeps(mode: 'build' | 'serve') {
61
64
  'tamagui/linear-gradient',
62
65
  '@tamagui/linear-gradient',
63
66
  '@react-native/normalize-color',
64
- 'vxs',
65
- 'vxs/server-render',
66
67
  'expo-modules-core',
67
68
  'expo-status-bar',
68
69
  'react-native-web',
@@ -3,7 +3,14 @@ import createViteFlow from '@vxrn/vite-flow'
3
3
  import viteReactPlugin from '@vxrn/vite-native-swc'
4
4
  import { readFile } from 'node:fs/promises'
5
5
  import { dirname, join, relative } from 'node:path'
6
- import { build, mergeConfig, resolveConfig, transformWithEsbuild, type InlineConfig } from 'vite'
6
+ import {
7
+ build,
8
+ createBuilder,
9
+ mergeConfig,
10
+ resolveConfig,
11
+ transformWithEsbuild,
12
+ type InlineConfig,
13
+ } from 'vite'
7
14
  import { nativeExtensions } from '../constants'
8
15
  import { resolveFile } from './resolveFile'
9
16
  import { isBuildingNativeBundle, setIsBuildingNativeBundle } from './isBuildingNativeBundle'
@@ -153,7 +160,9 @@ export async function getReactNativeBundle(options: VXRNConfigFilled, viteRNClie
153
160
  // // this fixes my swap-react-native plugin not being called pre 😳
154
161
  await resolveConfig(nativeBuildConfig, 'build')
155
162
 
156
- const buildOutput = await build(nativeBuildConfig)
163
+ const builder = await createBuilder(nativeBuildConfig)
164
+
165
+ const buildOutput = await builder.build(builder.environments.ios)
157
166
 
158
167
  if (!('output' in buildOutput)) {
159
168
  throw `❌`
package/types/index.d.ts CHANGED
@@ -4,5 +4,6 @@ export { serve } from './exports/serve';
4
4
  export * from './utils/getOptionsFilled';
5
5
  export * from './utils/getOptimizeDeps';
6
6
  export * from './utils/getBaseViteConfig';
7
+ export * from './utils/environmentUtils';
7
8
  export * from './types';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { Plugin } from 'vite';
1
+ import { type Plugin } from 'vite';
2
2
  export declare function reactNativeCommonJsPlugin(options: {
3
3
  root: string;
4
4
  port: number;
@@ -1,10 +1,6 @@
1
1
  import type { VXRNConfigFilled } from '../utils/getOptionsFilled';
2
2
  export declare function reactNativeHMRPlugin({ root }: VXRNConfigFilled): {
3
3
  name: string;
4
- handleHotUpdate({ read, modules, file }: {
5
- read: any;
6
- modules: any;
7
- file: any;
8
- }): Promise<void>;
4
+ handleHotUpdate(this: void, { read, modules, file }: import("vite").HmrContext): Promise<void>;
9
5
  };
10
6
  //# sourceMappingURL=reactNativeHMRPlugin.d.ts.map
@@ -0,0 +1,6 @@
1
+ import type { Environment } from 'vite';
2
+ export declare function isWebEnvironment(environment: Environment): boolean;
3
+ export declare function isNativeEnvironment(environment: Environment): boolean;
4
+ export declare function isIOSEnvironment(environment: Environment): boolean;
5
+ export declare function isAndroidEnvironment(environment: Environment): boolean;
6
+ //# sourceMappingURL=environmentUtils.d.ts.map
@@ -1,58 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
- mod
22
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
- var bindKeypressInput_exports = {};
24
- __export(bindKeypressInput_exports, {
25
- bindKeypressInput: () => bindKeypressInput
26
- });
27
- module.exports = __toCommonJS(bindKeypressInput_exports);
28
- var import_node_readline = __toESM(require("node:readline"), 1);
29
- function bindKeypressInput() {
30
- if (!process.stdin.setRawMode) {
31
- console.warn({
32
- msg: "Interactive mode is not supported in this environment"
33
- });
34
- return;
35
- }
36
- import_node_readline.default.emitKeypressEvents(process.stdin), process.stdin.setRawMode(!0), process.stdin.on("keypress", (_key, data) => {
37
- const { ctrl, name } = data;
38
- if (ctrl === !0)
39
- switch (name) {
40
- case "c":
41
- process.exit();
42
- case "z":
43
- process.emit("SIGTSTP", "SIGTSTP");
44
- break;
45
- }
46
- else
47
- switch (name) {
48
- case "r":
49
- break;
50
- case "d":
51
- break;
52
- case "c":
53
- process.stdout.write("\x1B[2J\x1B[0;0H");
54
- break;
55
- }
56
- });
57
- }
58
- //# sourceMappingURL=bindKeypressInput.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/exports/bindKeypressInput.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAAqB;AAEd,SAAS,oBAAoB;AAClC,MAAI,CAAC,QAAQ,MAAM,YAAY;AAC7B,YAAQ,KAAK;AAAA,MACX,KAAK;AAAA,IACP,CAAC;AACD;AAAA,EACF;AAEA,uBAAAA,QAAS,mBAAmB,QAAQ,KAAK,GACzC,QAAQ,MAAM,WAAW,EAAI,GAE7B,QAAQ,MAAM,GAAG,YAAY,CAAC,MAAM,SAAS;AAC3C,UAAM,EAAE,MAAM,KAAK,IAAI;AACvB,QAAI,SAAS;AACX,cAAQ,MAAM;AAAA,QAEZ,KAAK;AACH,kBAAQ,KAAK;AAAA,QACf,KAAK;AACH,kBAAQ,KAAK,WAAW,SAAS;AACjC;AAAA,MACJ;AAAA;AAEA,cAAQ,MAAM;AAAA,QACZ,KAAK;AAKH;AAAA,QACF,KAAK;AAKH;AAAA,QACF,KAAK;AACH,kBAAQ,OAAO,MAAM,kBAAsB;AAE3C;AAAA,MACJ;AAAA,EAEJ,CAAC;AACH;",
5
- "names": ["readline"]
6
- }
@@ -1,63 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: !0 });
10
- }, __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from == "object" || typeof from == "function")
12
- for (let key of __getOwnPropNames(from))
13
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- return to;
15
- };
16
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
- // If the importer is in node compatibility mode or this is not an ESM
18
- // file that has been converted to a CommonJS file using a Babel-
19
- // compatible transform (i.e. "__esModule" has not been set), then set
20
- // "default" to the CommonJS "module.exports" for node compatibility.
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
22
- mod
23
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
24
- var bindKeypressInput_exports = {};
25
- __export(bindKeypressInput_exports, {
26
- bindKeypressInput: () => bindKeypressInput
27
- });
28
- module.exports = __toCommonJS(bindKeypressInput_exports);
29
- var import_node_readline = __toESM(require("node:readline"), 1);
30
- function bindKeypressInput() {
31
- if (!process.stdin.setRawMode) {
32
- console.warn({
33
- msg: "Interactive mode is not supported in this environment"
34
- });
35
- return;
36
- }
37
- import_node_readline.default.emitKeypressEvents(process.stdin), process.stdin.setRawMode(!0), process.stdin.on("keypress", function(_key, data) {
38
- var ctrl = data.ctrl, name = data.name;
39
- if (ctrl === !0)
40
- switch (name) {
41
- case "c":
42
- process.exit();
43
- case "z":
44
- process.emit("SIGTSTP", "SIGTSTP");
45
- break;
46
- }
47
- else
48
- switch (name) {
49
- case "r":
50
- break;
51
- case "d":
52
- break;
53
- case "c":
54
- process.stdout.write("\x1B[2J\x1B[0;0H");
55
- break;
56
- }
57
- });
58
- }
59
- // Annotate the CommonJS export names for ESM import in node:
60
- 0 && (module.exports = {
61
- bindKeypressInput
62
- });
63
- //# sourceMappingURL=bindKeypressInput.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/exports/Users/n8/vxrn/packages/vxrn/src/exports/bindKeypressInput.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;2BAAqB;AAEd,SAASA,oBAAAA;AACd,MAAI,CAACC,QAAQC,MAAMC,YAAY;AAC7BC,YAAQC,KAAK;MACXC,KAAK;IACP,CAAA;AACA;EACF;AAEAC,uBAAAA,QAASC,mBAAmBP,QAAQC,KAAK,GACzCD,QAAQC,MAAMC,WAAW,EAAA,GAEzBF,QAAQC,MAAMO,GAAG,YAAY,SAACC,MAAMC,MAAAA;AAClC,QAAQC,OAAeD,KAAfC,MAAMC,OAASF,KAATE;AACd,QAAID,SAAS;AACX,cAAQC,MAAAA;QAEN,KAAK;AACHZ,kBAAQa,KAAI;QACd,KAAK;AACHb,kBAAQc,KAAK,WAAW,SAAA;AACxB;MACJ;;AAEA,cAAQF,MAAAA;QACN,KAAK;AAKH;QACF,KAAK;AAKH;QACF,KAAK;AACHZ,kBAAQe,OAAOC,MAAM,kBAAA;AAErB;MACJ;EAEJ,CAAA;AACF;",
5
- "names": ["bindKeypressInput", "process", "stdin", "setRawMode", "console", "warn", "msg", "readline", "emitKeypressEvents", "on", "_key", "data", "ctrl", "name", "exit", "emit", "stdout", "write"]
6
- }
@@ -1,23 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: !0 });
8
- }, __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from == "object" || typeof from == "function")
10
- for (let key of __getOwnPropNames(from))
11
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
- var coerceToArray_exports = {};
16
- __export(coerceToArray_exports, {
17
- coerceToArray: () => coerceToArray
18
- });
19
- module.exports = __toCommonJS(coerceToArray_exports);
20
- function coerceToArray(thing) {
21
- return Array.isArray(thing) ? thing : [thing];
22
- }
23
- //# sourceMappingURL=coerceToArray.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/exports/coerceToArray.ts"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,SAAS,cAAiB,OAAqB;AACpD,SAAO,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK;AAC9C;",
5
- "names": []
6
- }