vite-plugin-react-native 0.0.2 → 0.0.4
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.cjs +34 -4
- package/dist/index.js +33 -4
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var path = require('path');
|
|
4
|
+
var fs = require('fs');
|
|
5
|
+
var module$1 = require('module');
|
|
4
6
|
var url = require('url');
|
|
5
7
|
|
|
6
8
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
7
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
10
|
|
|
9
11
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
12
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
10
13
|
|
|
11
14
|
// index.ts
|
|
12
15
|
function uniqueStrings(values) {
|
|
@@ -39,25 +42,35 @@ function reactNative() {
|
|
|
39
42
|
const screensId = "virtual:rn-screens";
|
|
40
43
|
const resolvedScreensId = "\0" + screensId;
|
|
41
44
|
const pluginDir = path__default.default.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
42
|
-
const
|
|
43
|
-
const routerDomSourceEntry = path__default.default.join(projectRoot, "node_modules/react-native-router-dom/src/index.ts");
|
|
45
|
+
const require2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
44
46
|
return {
|
|
45
47
|
name: "react-native",
|
|
46
48
|
enforce: "pre",
|
|
47
49
|
config(userConfig, env) {
|
|
48
50
|
const mode = env.mode;
|
|
49
51
|
const isProd = mode === "production";
|
|
52
|
+
const projectRoot = userConfig.root ? path__default.default.resolve(userConfig.root) : process.cwd();
|
|
53
|
+
const routerDomPackageJson = require2.resolve("react-native-router-dom/package.json", { paths: [projectRoot, pluginDir] });
|
|
54
|
+
const routerDomDir = path__default.default.dirname(routerDomPackageJson);
|
|
55
|
+
const routerDomSourceEntry = path__default.default.join(routerDomDir, "src/index.ts");
|
|
56
|
+
const routerDomDistEntry = path__default.default.join(routerDomDir, "dist/index.mjs");
|
|
57
|
+
const routerDomEntry = fs__default.default.existsSync(routerDomSourceEntry) ? routerDomSourceEntry : routerDomDistEntry;
|
|
50
58
|
const userAlias = userConfig.resolve?.alias;
|
|
51
59
|
const userAliasArray = Array.isArray(userAlias) ? userAlias : userAlias && typeof userAlias === "object" ? Object.entries(userAlias).map(([find, replacement]) => ({ find, replacement })) : [];
|
|
52
60
|
const userResolveExtensions = Array.isArray(userConfig.resolve?.extensions) ? userConfig.resolve?.extensions : null;
|
|
53
61
|
const userOptimizeDepsExclude = Array.isArray(userConfig.optimizeDeps?.exclude) ? userConfig.optimizeDeps?.exclude : [];
|
|
54
62
|
const userOptimizeDepsInclude = Array.isArray(userConfig.optimizeDeps?.include) ? userConfig.optimizeDeps?.include : [];
|
|
63
|
+
const userOptimizeDepsEsbuildOptions = userConfig.optimizeDeps?.esbuildOptions && typeof userConfig.optimizeDeps.esbuildOptions === "object" ? userConfig.optimizeDeps.esbuildOptions : {};
|
|
55
64
|
const config = {
|
|
56
65
|
resolve: {
|
|
57
66
|
alias: [
|
|
58
67
|
...userAliasArray,
|
|
59
68
|
{ find: /^react-native$/, replacement: "react-native-web" },
|
|
60
|
-
{ find: /^react-native-router-dom$/, replacement:
|
|
69
|
+
{ find: /^react-native-router-dom$/, replacement: routerDomEntry },
|
|
70
|
+
{ find: /^inline-style-prefixer\/lib\/plugins\/(.*)$/, replacement: "inline-style-prefixer/es/plugins/$1" },
|
|
71
|
+
{ find: "react-native/Libraries/EventEmitter/RCTDeviceEventEmitter", replacement: "react-native-web/dist/vendor/react-native/NativeEventEmitter/RCTDeviceEventEmitter" },
|
|
72
|
+
{ find: "react-native/Libraries/vendor/emitter/EventEmitter", replacement: "react-native-web/dist/vendor/react-native/emitter/EventEmitter" },
|
|
73
|
+
{ find: "react-native/Libraries/EventEmitter/NativeEventEmitter", replacement: "react-native-web/dist/vendor/react-native/NativeEventEmitter" }
|
|
61
74
|
],
|
|
62
75
|
dedupe: ["react", "react-dom"],
|
|
63
76
|
extensions: userResolveExtensions ? void 0 : webResolveExtensions
|
|
@@ -75,6 +88,14 @@ function reactNative() {
|
|
|
75
88
|
global: "globalThis"
|
|
76
89
|
},
|
|
77
90
|
optimizeDeps: {
|
|
91
|
+
esbuildOptions: {
|
|
92
|
+
...userOptimizeDepsEsbuildOptions,
|
|
93
|
+
resolveExtensions: "resolveExtensions" in userOptimizeDepsEsbuildOptions ? userOptimizeDepsEsbuildOptions.resolveExtensions : userResolveExtensions ?? webResolveExtensions,
|
|
94
|
+
loader: {
|
|
95
|
+
..."loader" in userOptimizeDepsEsbuildOptions ? userOptimizeDepsEsbuildOptions.loader : {},
|
|
96
|
+
".js": "jsx"
|
|
97
|
+
}
|
|
98
|
+
},
|
|
78
99
|
include: uniqueStrings([
|
|
79
100
|
...userOptimizeDepsInclude,
|
|
80
101
|
"react",
|
|
@@ -82,7 +103,16 @@ function reactNative() {
|
|
|
82
103
|
"react/jsx-runtime",
|
|
83
104
|
"react/jsx-dev-runtime",
|
|
84
105
|
"hoist-non-react-statics",
|
|
85
|
-
"invariant"
|
|
106
|
+
"invariant",
|
|
107
|
+
"react-native-web",
|
|
108
|
+
"react-native-reanimated",
|
|
109
|
+
"react-native-css-interop",
|
|
110
|
+
"react-native-router-dom",
|
|
111
|
+
"react-native-i18njs",
|
|
112
|
+
"@react-native/normalize-colors",
|
|
113
|
+
"inline-style-prefixer",
|
|
114
|
+
"inline-style-prefixer/lib/plugins/crossFade",
|
|
115
|
+
"css-in-js-utils"
|
|
86
116
|
]),
|
|
87
117
|
exclude: uniqueStrings([
|
|
88
118
|
...userOptimizeDepsExclude,
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { createRequire } from 'module';
|
|
2
4
|
import { fileURLToPath } from 'url';
|
|
3
5
|
|
|
4
6
|
// index.ts
|
|
@@ -32,25 +34,35 @@ function reactNative() {
|
|
|
32
34
|
const screensId = "virtual:rn-screens";
|
|
33
35
|
const resolvedScreensId = "\0" + screensId;
|
|
34
36
|
const pluginDir = path.dirname(fileURLToPath(import.meta.url));
|
|
35
|
-
const
|
|
36
|
-
const routerDomSourceEntry = path.join(projectRoot, "node_modules/react-native-router-dom/src/index.ts");
|
|
37
|
+
const require2 = createRequire(import.meta.url);
|
|
37
38
|
return {
|
|
38
39
|
name: "react-native",
|
|
39
40
|
enforce: "pre",
|
|
40
41
|
config(userConfig, env) {
|
|
41
42
|
const mode = env.mode;
|
|
42
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;
|
|
43
50
|
const userAlias = userConfig.resolve?.alias;
|
|
44
51
|
const userAliasArray = Array.isArray(userAlias) ? userAlias : userAlias && typeof userAlias === "object" ? Object.entries(userAlias).map(([find, replacement]) => ({ find, replacement })) : [];
|
|
45
52
|
const userResolveExtensions = Array.isArray(userConfig.resolve?.extensions) ? userConfig.resolve?.extensions : null;
|
|
46
53
|
const userOptimizeDepsExclude = Array.isArray(userConfig.optimizeDeps?.exclude) ? userConfig.optimizeDeps?.exclude : [];
|
|
47
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 : {};
|
|
48
56
|
const config = {
|
|
49
57
|
resolve: {
|
|
50
58
|
alias: [
|
|
51
59
|
...userAliasArray,
|
|
52
60
|
{ find: /^react-native$/, replacement: "react-native-web" },
|
|
53
|
-
{ find: /^react-native-router-dom$/, replacement:
|
|
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" }
|
|
54
66
|
],
|
|
55
67
|
dedupe: ["react", "react-dom"],
|
|
56
68
|
extensions: userResolveExtensions ? void 0 : webResolveExtensions
|
|
@@ -68,6 +80,14 @@ function reactNative() {
|
|
|
68
80
|
global: "globalThis"
|
|
69
81
|
},
|
|
70
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
|
+
},
|
|
71
91
|
include: uniqueStrings([
|
|
72
92
|
...userOptimizeDepsInclude,
|
|
73
93
|
"react",
|
|
@@ -75,7 +95,16 @@ function reactNative() {
|
|
|
75
95
|
"react/jsx-runtime",
|
|
76
96
|
"react/jsx-dev-runtime",
|
|
77
97
|
"hoist-non-react-statics",
|
|
78
|
-
"invariant"
|
|
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"
|
|
79
108
|
]),
|
|
80
109
|
exclude: uniqueStrings([
|
|
81
110
|
...userOptimizeDepsExclude,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-react-native",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Vite plugin for React Native web compatibility",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -45,4 +45,4 @@
|
|
|
45
45
|
"typescript": "^5.0.0",
|
|
46
46
|
"vite": "^7.0.0"
|
|
47
47
|
}
|
|
48
|
-
}
|
|
48
|
+
}
|