vite-plugin-react-native 0.0.4 → 1.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.
package/dist/index.js CHANGED
@@ -1,21 +1,12 @@
1
- import path from 'path';
1
+ import path2 from 'path';
2
2
  import fs from 'fs';
3
3
  import { createRequire } from 'module';
4
4
  import { fileURLToPath } from 'url';
5
+ import { transformWithEsbuild } from 'vite';
6
+ import flowRemoveTypes from 'flow-remove-types';
5
7
 
6
- // index.ts
7
- function uniqueStrings(values) {
8
- const out = [];
9
- const seen = /* @__PURE__ */ new Set();
10
- for (const v of values) {
11
- if (!v) continue;
12
- if (seen.has(v)) continue;
13
- seen.add(v);
14
- out.push(v);
15
- }
16
- return out;
17
- }
18
- var webResolveExtensions = [
8
+ // src/index.ts
9
+ var RESOLVE_EXTENSIONS = [
19
10
  ".web.mjs",
20
11
  ".web.js",
21
12
  ".web.ts",
@@ -28,103 +19,290 @@ var webResolveExtensions = [
28
19
  ".jsx",
29
20
  ".json"
30
21
  ];
31
- function reactNative() {
32
- const safeAreaId = "virtual:rn-safe-area-context";
33
- const resolvedSafeAreaId = "\0" + safeAreaId;
34
- const screensId = "virtual:rn-screens";
35
- const resolvedScreensId = "\0" + screensId;
36
- const pluginDir = path.dirname(fileURLToPath(import.meta.url));
37
- const require2 = createRequire(import.meta.url);
22
+ var MODULE_TYPES = { ".js": "jsx", ".mjs": "jsx", ".cjs": "jsx", ".flow": "jsx" };
23
+ var TREESHAKE_SAFE_PRESET = {
24
+ annotations: true,
25
+ invalidImportSideEffects: true,
26
+ manualPureFunctions: [],
27
+ moduleSideEffects: true,
28
+ propertyReadSideEffects: "always",
29
+ unknownGlobalSideEffects: true,
30
+ propertyWriteSideEffects: "always"
31
+ };
32
+ var CORE_OPTIMIZE_DEPS_INCLUDE = [
33
+ "react",
34
+ "react-dom",
35
+ "react/jsx-runtime",
36
+ "react/jsx-dev-runtime",
37
+ "react-native-web"
38
+ ];
39
+ var OPTIONAL_OPTIMIZE_DEPS_INCLUDE = [
40
+ "hoist-non-react-statics",
41
+ "invariant",
42
+ "react-native-reanimated",
43
+ "react-native-css-interop",
44
+ "react-native-i18njs",
45
+ "@react-native/normalize-colors",
46
+ "inline-style-prefixer",
47
+ "inline-style-prefixer/lib/plugins/crossFade",
48
+ "css-in-js-utils"
49
+ ];
50
+ function uniqueStrings(values) {
51
+ const seen = /* @__PURE__ */ new Set();
52
+ const out = [];
53
+ for (const v of values) {
54
+ if (!v || seen.has(v)) continue;
55
+ seen.add(v);
56
+ out.push(v);
57
+ }
58
+ return out;
59
+ }
60
+ function getViteMajorVersion(projectRoot, require2) {
61
+ try {
62
+ const pkgPath = require2.resolve("vite/package.json", {
63
+ paths: [projectRoot]
64
+ });
65
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
66
+ const v = String(pkg.version ?? "0");
67
+ const major = Number(v.split(".")[0]);
68
+ return Number.isFinite(major) ? major : 0;
69
+ } catch {
70
+ return 0;
71
+ }
72
+ }
73
+ function getInstalledOptimizeDepsInclude(projectRoot, routerDomEntry) {
74
+ const pkgPath = path2.join(projectRoot, "package.json");
75
+ let deps = {};
76
+ try {
77
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
78
+ deps = { ...pkg.dependencies ?? {}, ...pkg.devDependencies ?? {} };
79
+ } catch {
80
+ return [...CORE_OPTIMIZE_DEPS_INCLUDE];
81
+ }
82
+ const installed = OPTIONAL_OPTIMIZE_DEPS_INCLUDE.filter((entry) => {
83
+ const pkgName = entry.split("/")[0];
84
+ return pkgName in deps;
85
+ });
86
+ const list = [...CORE_OPTIMIZE_DEPS_INCLUDE, ...installed];
87
+ if (routerDomEntry && "react-native-router-dom" in deps) {
88
+ list.push("react-native-router-dom");
89
+ }
90
+ return list;
91
+ }
92
+ var DOCTOR_PATTERN = /return\s*<react-native-css-interop-jsx-pragma-check\s*\/>\s*===\s*true\s*;/g;
93
+ function flowRemoveTypesPlugin() {
38
94
  return {
39
- name: "react-native",
40
- enforce: "pre",
41
- config(userConfig, env) {
42
- const mode = env.mode;
43
- const isProd = mode === "production";
44
- const projectRoot = userConfig.root ? path.resolve(userConfig.root) : process.cwd();
45
- const routerDomPackageJson = require2.resolve("react-native-router-dom/package.json", { paths: [projectRoot, pluginDir] });
46
- const routerDomDir = path.dirname(routerDomPackageJson);
47
- const routerDomSourceEntry = path.join(routerDomDir, "src/index.ts");
48
- const routerDomDistEntry = path.join(routerDomDir, "dist/index.mjs");
49
- const routerDomEntry = fs.existsSync(routerDomSourceEntry) ? routerDomSourceEntry : routerDomDistEntry;
50
- const userAlias = userConfig.resolve?.alias;
51
- const userAliasArray = Array.isArray(userAlias) ? userAlias : userAlias && typeof userAlias === "object" ? Object.entries(userAlias).map(([find, replacement]) => ({ find, replacement })) : [];
52
- const userResolveExtensions = Array.isArray(userConfig.resolve?.extensions) ? userConfig.resolve?.extensions : null;
53
- const userOptimizeDepsExclude = Array.isArray(userConfig.optimizeDeps?.exclude) ? userConfig.optimizeDeps?.exclude : [];
54
- const userOptimizeDepsInclude = Array.isArray(userConfig.optimizeDeps?.include) ? userConfig.optimizeDeps?.include : [];
55
- const userOptimizeDepsEsbuildOptions = userConfig.optimizeDeps?.esbuildOptions && typeof userConfig.optimizeDeps.esbuildOptions === "object" ? userConfig.optimizeDeps.esbuildOptions : {};
56
- const config = {
57
- resolve: {
58
- alias: [
59
- ...userAliasArray,
60
- { find: /^react-native$/, replacement: "react-native-web" },
61
- { find: /^react-native-router-dom$/, replacement: routerDomEntry },
62
- { find: /^inline-style-prefixer\/lib\/plugins\/(.*)$/, replacement: "inline-style-prefixer/es/plugins/$1" },
63
- { find: "react-native/Libraries/EventEmitter/RCTDeviceEventEmitter", replacement: "react-native-web/dist/vendor/react-native/NativeEventEmitter/RCTDeviceEventEmitter" },
64
- { find: "react-native/Libraries/vendor/emitter/EventEmitter", replacement: "react-native-web/dist/vendor/react-native/emitter/EventEmitter" },
65
- { find: "react-native/Libraries/EventEmitter/NativeEventEmitter", replacement: "react-native-web/dist/vendor/react-native/NativeEventEmitter" }
66
- ],
67
- dedupe: ["react", "react-dom"],
68
- extensions: userResolveExtensions ? void 0 : webResolveExtensions
69
- },
70
- build: {
71
- commonjsOptions: {
72
- esmExternals: true,
73
- requireReturnsDefault: "auto",
74
- transformMixedEsModules: true
75
- }
76
- },
77
- define: {
78
- __DEV__: JSON.stringify(!isProd),
79
- "process.env.NODE_ENV": JSON.stringify(mode),
80
- global: "globalThis"
81
- },
82
- optimizeDeps: {
83
- esbuildOptions: {
84
- ...userOptimizeDepsEsbuildOptions,
85
- resolveExtensions: "resolveExtensions" in userOptimizeDepsEsbuildOptions ? userOptimizeDepsEsbuildOptions.resolveExtensions : userResolveExtensions ?? webResolveExtensions,
86
- loader: {
87
- ..."loader" in userOptimizeDepsEsbuildOptions ? userOptimizeDepsEsbuildOptions.loader : {},
88
- ".js": "jsx"
89
- }
90
- },
91
- include: uniqueStrings([
92
- ...userOptimizeDepsInclude,
93
- "react",
94
- "react-dom",
95
- "react/jsx-runtime",
96
- "react/jsx-dev-runtime",
97
- "hoist-non-react-statics",
98
- "invariant",
99
- "react-native-web",
100
- "react-native-reanimated",
101
- "react-native-css-interop",
102
- "react-native-router-dom",
103
- "react-native-i18njs",
104
- "@react-native/normalize-colors",
105
- "inline-style-prefixer",
106
- "inline-style-prefixer/lib/plugins/crossFade",
107
- "css-in-js-utils"
108
- ]),
109
- exclude: uniqueStrings([
110
- ...userOptimizeDepsExclude,
111
- "react-native",
112
- "react-native-gesture-handler",
113
- "react-native-safe-area-context",
114
- "react-native-screens"
115
- ])
95
+ name: "flow-remove-types",
96
+ transform: {
97
+ filter: { code: /@flow/ },
98
+ handler(code) {
99
+ return { code: flowRemoveTypes(code).toString() };
100
+ }
101
+ }
102
+ };
103
+ }
104
+ function stripFlowTypes(code) {
105
+ try {
106
+ return flowRemoveTypes(code).toString();
107
+ } catch {
108
+ return code;
109
+ }
110
+ }
111
+ function treeshakeFixPlugin() {
112
+ return {
113
+ name: "treeshake-fix",
114
+ transform: {
115
+ handler(_code, id) {
116
+ if (id.includes("react-native-css-interop") || id.includes("react-native-css") || id.includes("expo-modules-core")) {
117
+ return { moduleSideEffects: "no-treeshake" };
116
118
  }
117
- };
118
- return config;
119
+ return null;
120
+ }
121
+ }
122
+ };
123
+ }
124
+ function transformCssInteropDoctorCheck(code, id) {
125
+ if (!id.includes("node_modules/react-native-css-interop") || !id.includes("dist/doctor.js")) {
126
+ return { code, map: null, changed: false };
127
+ }
128
+ const re = new RegExp(DOCTOR_PATTERN.source, "g");
129
+ if (!re.test(code)) return { code, map: null, changed: false };
130
+ re.lastIndex = 0;
131
+ return { code: code.replace(re, "return true;"), map: null, changed: true };
132
+ }
133
+ function analyzeReanimatedRequires(code, exportedVars) {
134
+ const importMap = /* @__PURE__ */ new Map();
135
+ for (const varName of exportedVars) {
136
+ const re = new RegExp(
137
+ `${varName}\\s*=\\s*[\\s\\S]*?require\\(['"]([^'"]+)['"]\\)(?:\\.([\\w]+))?`,
138
+ "g"
139
+ );
140
+ const m = re.exec(code);
141
+ if (m) {
142
+ const [, modulePath, prop] = m;
143
+ const key = `${modulePath}:${prop || "default"}`;
144
+ if (!importMap.has(key)) importMap.set(key, []);
145
+ importMap.get(key).push(varName);
146
+ }
147
+ }
148
+ return importMap;
149
+ }
150
+ function generateReanimatedExports(importMap) {
151
+ let out = "";
152
+ for (const [key, vars] of importMap) {
153
+ const [modulePath, prop] = key.split(":");
154
+ for (const v of vars) {
155
+ out += prop === "default" ? `export { default as ${v} } from '${modulePath}';
156
+ ` : `export { ${prop} as ${v} } from '${modulePath}';
157
+ `;
158
+ }
159
+ }
160
+ return out;
161
+ }
162
+ var REANIMATED_TRY_CATCH_RE = /try\s*\{[^{}]*?require\([^)]+\)[^{}]*?\}\s*catch[^{}]*?\{[^{}]*?\}/gs;
163
+ function transformReanimatedWebUtils(code, id, isProduction) {
164
+ if (!isProduction || !id.includes("node_modules/react-native-reanimated") || !id.includes("ReanimatedModule/js-reanimated/webUtils") || !code.includes("export let") || !code.includes("try") || !code.includes("require")) {
165
+ return { code, map: null, changed: false };
166
+ }
167
+ const exportLetMatches = [...code.matchAll(/export let (\w+);/g)];
168
+ const exportedVars = exportLetMatches.map((m) => m[1]);
169
+ if (!exportedVars.length) return { code, map: null, changed: false };
170
+ const importMap = analyzeReanimatedRequires(code, exportedVars);
171
+ let result = code.replace(REANIMATED_TRY_CATCH_RE, "\n").replace(/export let \w+;/g, "");
172
+ const exports$1 = generateReanimatedExports(importMap);
173
+ if (!exports$1) return { code, map: null, changed: false };
174
+ result = result.trimEnd() + "\n\n" + exports$1;
175
+ return { code: result, map: null, changed: true };
176
+ }
177
+
178
+ // src/config.ts
179
+ function normalizeUserAlias(alias) {
180
+ if (Array.isArray(alias)) return alias;
181
+ if (alias && typeof alias === "object") {
182
+ return Object.entries(alias).map(([find, replacement]) => ({ find, replacement: String(replacement) }));
183
+ }
184
+ return [];
185
+ }
186
+ function buildResolveAlias(options) {
187
+ const { userAliasArray, routerDomEntry } = options;
188
+ const alias = [...userAliasArray];
189
+ if (routerDomEntry) {
190
+ alias.push({ find: /^react-native-router-dom$/, replacement: routerDomEntry });
191
+ }
192
+ alias.push(
193
+ { find: /^react-native\/(?!Libraries\/Core\/Devtools\/openURLInBrowser$)(.*)$/, replacement: "react-native-web/$1" },
194
+ { find: "inline-style-prefixer/lib/createPrefixer", replacement: "inline-style-prefixer/es/createPrefixer" },
195
+ { find: /^inline-style-prefixer\/lib\/plugins\/(.*)$/, replacement: "inline-style-prefixer/es/plugins/$1" },
196
+ { find: /^css-in-js-utils\/lib\/(.*)$/, replacement: "css-in-js-utils/es/$1" },
197
+ { find: "react-native/Libraries/EventEmitter/RCTDeviceEventEmitter", replacement: "react-native-web/dist/vendor/react-native/NativeEventEmitter/RCTDeviceEventEmitter" },
198
+ { find: "react-native/Libraries/vendor/emitter/EventEmitter", replacement: "react-native-web/dist/vendor/react-native/emitter/EventEmitter" },
199
+ { find: "react-native/Libraries/EventEmitter/NativeEventEmitter", replacement: "react-native-web/dist/vendor/react-native/NativeEventEmitter" }
200
+ );
201
+ return alias;
202
+ }
203
+ function buildViteConfig(ctx) {
204
+ const { mode, userConfig, resolveExtensions, useRolldown, installedInclude, routerDomEntry } = ctx;
205
+ const isProd = mode === "production";
206
+ const userAliasArray = normalizeUserAlias(userConfig.resolve?.alias ?? []);
207
+ const alias = buildResolveAlias({ userAliasArray, routerDomEntry });
208
+ const od = userConfig.optimizeDeps;
209
+ const userOptimizeDepsExclude = Array.isArray(od?.exclude) ? od.exclude : [];
210
+ const userOptimizeDepsInclude = Array.isArray(od?.include) ? od.include : [];
211
+ const userEsbuildOptions = od?.esbuildOptions && typeof od.esbuildOptions === "object" ? od.esbuildOptions : {};
212
+ const userRolldownOptions = od?.rolldownOptions && typeof od.rolldownOptions === "object" ? od.rolldownOptions : void 0;
213
+ const rolldownPlugins = [flowRemoveTypesPlugin(), treeshakeFixPlugin()];
214
+ return {
215
+ resolve: {
216
+ alias,
217
+ dedupe: ["react", "react-dom"],
218
+ extensions: Array.isArray(userConfig.resolve?.extensions) ? void 0 : [...resolveExtensions]
119
219
  },
120
- resolveId(source) {
121
- if (source === "react-native-safe-area-context") return resolvedSafeAreaId;
122
- if (source === "react-native-screens") return resolvedScreensId;
123
- return null;
220
+ build: useRolldown ? {
221
+ rolldownOptions: {
222
+ resolve: { extensions: [...resolveExtensions] },
223
+ shimMissingExports: true,
224
+ treeshake: TREESHAKE_SAFE_PRESET,
225
+ moduleTypes: MODULE_TYPES,
226
+ plugins: rolldownPlugins
227
+ }
228
+ } : {
229
+ commonjsOptions: {
230
+ esmExternals: true,
231
+ requireReturnsDefault: "auto",
232
+ transformMixedEsModules: true
233
+ }
124
234
  },
125
- load(id) {
126
- if (id === resolvedSafeAreaId) {
127
- return `
235
+ define: {
236
+ __DEV__: JSON.stringify(!isProd),
237
+ "process.env.NODE_ENV": JSON.stringify(mode),
238
+ "process.env.EXPO_OS": JSON.stringify("web"),
239
+ global: "globalThis",
240
+ _WORKLET: false,
241
+ EXPO_OS: JSON.stringify("web")
242
+ },
243
+ optimizeDeps: {
244
+ ...useRolldown ? {
245
+ rolldownOptions: {
246
+ ...userRolldownOptions,
247
+ resolve: {
248
+ ...userRolldownOptions?.resolve,
249
+ extensions: [...resolveExtensions]
250
+ },
251
+ shimMissingExports: true,
252
+ treeshake: TREESHAKE_SAFE_PRESET,
253
+ moduleTypes: MODULE_TYPES,
254
+ plugins: [
255
+ ...rolldownPlugins,
256
+ ...userRolldownOptions?.plugins ?? []
257
+ ]
258
+ }
259
+ } : {
260
+ esbuildOptions: {
261
+ ...userEsbuildOptions,
262
+ resolveExtensions: "resolveExtensions" in userEsbuildOptions ? userEsbuildOptions.resolveExtensions : resolveExtensions,
263
+ loader: {
264
+ ..."loader" in userEsbuildOptions ? userEsbuildOptions.loader : {},
265
+ ".js": "jsx"
266
+ }
267
+ }
268
+ },
269
+ include: uniqueStrings([...userOptimizeDepsInclude, ...installedInclude]),
270
+ exclude: uniqueStrings([
271
+ ...userOptimizeDepsExclude,
272
+ "react-native",
273
+ "react-native-gesture-handler",
274
+ "react-native-safe-area-context",
275
+ "react-native-screens",
276
+ "@react-native/new-app-screen"
277
+ ])
278
+ }
279
+ };
280
+ }
281
+
282
+ // src/virtuals.ts
283
+ var VIRTUAL_RN_WEB = "virtual:rn-web";
284
+ var VIRTUAL_OPEN_URL_IN_BROWSER = "virtual:rn-openURLInBrowser";
285
+ var VIRTUAL_SAFE_AREA = "virtual:rn-safe-area-context";
286
+ var VIRTUAL_SCREENS = "virtual:rn-screens";
287
+ var VIRTUAL_GESTURE_HANDLER = "virtual:rn-gesture-handler";
288
+ var RESOLVED_RN_WEB = "\0" + VIRTUAL_RN_WEB;
289
+ var RESOLVED_OPEN_URL_IN_BROWSER = "\0" + VIRTUAL_OPEN_URL_IN_BROWSER;
290
+ var RESOLVED_SAFE_AREA = "\0" + VIRTUAL_SAFE_AREA;
291
+ var RESOLVED_SCREENS = "\0" + VIRTUAL_SCREENS;
292
+ var RESOLVED_GESTURE_HANDLER = "\0" + VIRTUAL_GESTURE_HANDLER;
293
+ var RN_LIBRARIES_OPEN_URL = "react-native/Libraries/Core/Devtools/openURLInBrowser";
294
+ function getVirtualModuleContent(id) {
295
+ if (id === RESOLVED_RN_WEB) {
296
+ return [
297
+ "export * from 'react-native-web';",
298
+ "export const ReactNativeVersion = { major: 0, minor: 84, patch: 1, prerelease: null, getVersionString() { return this.major + '.' + this.minor + '.' + this.patch + (this.prerelease ? '-' + this.prerelease : ''); } };"
299
+ ].join("\n");
300
+ }
301
+ if (id === RESOLVED_OPEN_URL_IN_BROWSER) {
302
+ return "export default function openURLInBrowser(url) { if (typeof window !== 'undefined' && url) window.open(url, '_blank'); }\n";
303
+ }
304
+ if (id === RESOLVED_SAFE_AREA) {
305
+ return `
128
306
  import * as React from 'react';
129
307
  import { View } from 'react-native';
130
308
  export const SafeAreaInsetsContext = React.createContext(null);
@@ -161,9 +339,9 @@ export function SafeAreaView(props) {
161
339
  return React.createElement(View, props);
162
340
  }
163
341
  `;
164
- }
165
- if (id === resolvedScreensId) {
166
- return `
342
+ }
343
+ if (id === RESOLVED_SCREENS) {
344
+ return `
167
345
  import * as React from 'react';
168
346
  import { View } from 'react-native';
169
347
  export function enableScreens() {}
@@ -186,10 +364,151 @@ export function ScreenContainer(props) {
186
364
  return React.createElement(View, { ...rest, style: withFlex1Style(style) });
187
365
  }
188
366
  `;
367
+ }
368
+ if (id === RESOLVED_GESTURE_HANDLER) {
369
+ return `
370
+ import * as React from 'react';
371
+ import { View } from 'react-native';
372
+
373
+ export function GestureHandlerRootView(props) {
374
+ return React.createElement(View, props);
375
+ }
376
+
377
+ export const Gesture = {
378
+ Tap: () => null,
379
+ Pan: () => null,
380
+ Pinch: () => null,
381
+ LongPress: () => null,
382
+ Fling: () => null,
383
+ Native: () => null,
384
+ Manual: () => null,
385
+ Race: () => null,
386
+ Simultaneous: () => null,
387
+ Exclusive: () => null,
388
+ };
389
+ export function GestureDetector(props) {
390
+ return React.createElement(View, props);
391
+ }
392
+ export default { GestureHandlerRootView, Gesture, GestureDetector };
393
+ `;
394
+ }
395
+ return null;
396
+ }
397
+ function resolveVirtualId(source) {
398
+ if (source === "react-native") return RESOLVED_RN_WEB;
399
+ if (source === RN_LIBRARIES_OPEN_URL) return RESOLVED_OPEN_URL_IN_BROWSER;
400
+ if (source === "react-native-safe-area-context") return RESOLVED_SAFE_AREA;
401
+ if (source === "react-native-screens") return RESOLVED_SCREENS;
402
+ if (source === "react-native-gesture-handler") return RESOLVED_GESTURE_HANDLER;
403
+ return null;
404
+ }
405
+
406
+ // src/index.ts
407
+ function replaceRequireAssetsWithImports(code) {
408
+ const re = /require\s*\(\s*['"](\.\/assets\/[^'"]+)['"]\s*\)/g;
409
+ const matches = [...code.matchAll(re)];
410
+ if (!matches.length) return code;
411
+ const seen = /* @__PURE__ */ new Map();
412
+ const imports = [];
413
+ let i = 0;
414
+ for (const m of matches) {
415
+ const p = m[1];
416
+ if (seen.has(p)) continue;
417
+ const name = `__rn_asset_${i++}`;
418
+ seen.set(p, name);
419
+ imports.push(`import ${name} from '${p}';`);
420
+ }
421
+ let out = code.replace(re, (_, p) => seen.get(p) ?? _);
422
+ const at = Math.max(0, out.search(/\n?import\s+/));
423
+ return out.slice(0, at) + imports.join("\n") + "\n" + out.slice(at);
424
+ }
425
+ function reactNative() {
426
+ const pluginDir = path2.dirname(fileURLToPath(import.meta.url));
427
+ const require2 = createRequire(import.meta.url);
428
+ let buildMode = "development";
429
+ let useRolldown = false;
430
+ let transformWithOxcFn = null;
431
+ return {
432
+ name: "react-native",
433
+ enforce: "pre",
434
+ config(userConfig, env) {
435
+ buildMode = env.mode ?? "development";
436
+ const projectRoot = userConfig.root ? path2.resolve(userConfig.root) : process.cwd();
437
+ let routerDomEntry = null;
438
+ try {
439
+ const routerDomPkg = require2.resolve("react-native-router-dom/package.json", { paths: [projectRoot, pluginDir] });
440
+ const routerDomDir = path2.dirname(routerDomPkg);
441
+ routerDomEntry = fs.existsSync(path2.join(routerDomDir, "src/index.ts")) ? path2.join(routerDomDir, "src/index.ts") : path2.join(routerDomDir, "dist/index.mjs");
442
+ } catch {
443
+ }
444
+ useRolldown = getViteMajorVersion(projectRoot, require2) >= 8;
445
+ const resolveExtensions = userConfig.resolve?.extensions ?? [...RESOLVE_EXTENSIONS];
446
+ const installedInclude = getInstalledOptimizeDepsInclude(projectRoot, routerDomEntry);
447
+ const partial = buildViteConfig({
448
+ mode: buildMode,
449
+ userConfig,
450
+ resolveExtensions,
451
+ useRolldown,
452
+ installedInclude,
453
+ routerDomEntry
454
+ });
455
+ return partial;
456
+ },
457
+ resolveId(source) {
458
+ const resolved = resolveVirtualId(source);
459
+ return resolved ?? null;
460
+ },
461
+ load(id) {
462
+ const content = getVirtualModuleContent(id);
463
+ return content ?? null;
464
+ },
465
+ async transform(code, id) {
466
+ const idPath = id.split("?")[0];
467
+ const isNodeModulesJs = id.includes("node_modules") && /\.(js|jsx|mjs|cjs)$/.test(idPath);
468
+ const hasFlow = /@flow/.test(code);
469
+ const isReactNativePkg = /node_modules[/\\]@react-native[/\\]/.test(id) || /node_modules[/\\]react-native[/\\]/.test(id);
470
+ let resultCode = code;
471
+ if (isNodeModulesJs && (hasFlow || isReactNativePkg)) {
472
+ resultCode = stripFlowTypes(resultCode);
473
+ }
474
+ if (id.includes("node_modules/@react-native") && /require\s*\(\s*['"]\.\/assets\//.test(resultCode)) {
475
+ resultCode = replaceRequireAssetsWithImports(resultCode);
476
+ }
477
+ const cssInterop = transformCssInteropDoctorCheck(resultCode, id);
478
+ if (cssInterop.changed) resultCode = cssInterop.code;
479
+ const reanimated = transformReanimatedWebUtils(resultCode, id, buildMode === "production");
480
+ if (reanimated.changed) resultCode = reanimated.code;
481
+ if (id.includes("node_modules/@react-native") && /\.js$/.test(idPath) && /<[A-Za-z]/.test(resultCode)) {
482
+ if (useRolldown) {
483
+ if (transformWithOxcFn === null) {
484
+ try {
485
+ const vite = await import('vite');
486
+ if (typeof vite.transformWithOxc === "function") {
487
+ transformWithOxcFn = vite.transformWithOxc;
488
+ }
489
+ } catch {
490
+ }
491
+ }
492
+ if (transformWithOxcFn) {
493
+ const result2 = await transformWithOxcFn(resultCode, idPath, {
494
+ lang: "jsx",
495
+ sourcemap: true
496
+ });
497
+ return { code: result2.code, map: result2.map ?? null };
498
+ }
499
+ }
500
+ const result = await transformWithEsbuild(resultCode, idPath, {
501
+ loader: "jsx",
502
+ jsx: "automatic"
503
+ });
504
+ return { code: result.code, map: result.map ?? null };
505
+ }
506
+ if (resultCode !== code || cssInterop.changed || reanimated.changed) {
507
+ return { code: resultCode, map: null };
189
508
  }
190
509
  return null;
191
510
  }
192
511
  };
193
512
  }
194
513
 
195
- export { reactNative };
514
+ export { CORE_OPTIMIZE_DEPS_INCLUDE, MODULE_TYPES, OPTIONAL_OPTIMIZE_DEPS_INCLUDE, RESOLVE_EXTENSIONS, TREESHAKE_SAFE_PRESET, buildResolveAlias, flowRemoveTypesPlugin, getInstalledOptimizeDepsInclude, getViteMajorVersion, normalizeUserAlias, reactNative, stripFlowTypes, transformCssInteropDoctorCheck, transformReanimatedWebUtils, treeshakeFixPlugin, uniqueStrings };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-react-native",
3
- "version": "0.0.4",
3
+ "version": "1.0.1",
4
4
  "description": "Vite plugin for React Native web compatibility",
5
5
  "keywords": [
6
6
  "vite",
@@ -37,12 +37,15 @@
37
37
  "test": "echo \"Error: no test specified\" && exit 1"
38
38
  },
39
39
  "peerDependencies": {
40
- "vite": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
40
+ "vite": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
41
+ },
42
+ "dependencies": {
43
+ "flow-remove-types": "^2.305.1"
41
44
  },
42
45
  "devDependencies": {
43
46
  "@types/node": "^20.0.0",
44
47
  "tsup": "^8.5.1",
45
48
  "typescript": "^5.0.0",
46
- "vite": "^7.0.0"
49
+ "vite": "^8.0.0"
47
50
  }
48
51
  }