rsbuild-plugin-react-native-web 3.4.1 → 3.6.0
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.d.ts +71 -62
- package/dist/index.js +231 -211
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,62 +1,71 @@
|
|
|
1
|
-
import { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
interface
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
* @default '
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
1
|
+
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Rsbuild plugin for React Native Web support.
|
|
5
|
+
* This plugin enables you to use React Native components in web applications.
|
|
6
|
+
*/
|
|
7
|
+
export declare function pluginReactNativeWeb(options?: PluginReactNativeWebOptions): RsbuildPlugin;
|
|
8
|
+
|
|
9
|
+
export declare interface PluginReactNativeWebOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Whether React Native Web should run in development mode.
|
|
12
|
+
*
|
|
13
|
+
* `process.env.NODE_ENV` and `__DEV__` are resolved independently using this
|
|
14
|
+
* priority: `dev` > the corresponding existing define > the host environment.
|
|
15
|
+
* Define expressions are intentionally not parsed. If only `process.env.NODE_ENV`
|
|
16
|
+
* is customized while `dev` and `__DEV__` are unset, `__DEV__` falls back to the
|
|
17
|
+
* host environment and may disagree with that custom define. To keep them aligned,
|
|
18
|
+
* set `dev` or define `__DEV__` explicitly.
|
|
19
|
+
*/
|
|
20
|
+
dev?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Additional node_modules that need to be transpiled.
|
|
23
|
+
* By default, packages starting with `react-native`, `@react-native`, `expo`, and `@expo`
|
|
24
|
+
* are already included.
|
|
25
|
+
*
|
|
26
|
+
* @example ['my-react-native-library']
|
|
27
|
+
*/
|
|
28
|
+
modulesToTranspile?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* The JSX runtime to use.
|
|
31
|
+
* - 'automatic': Uses the new JSX transform (React 17+)
|
|
32
|
+
* - 'classic': Uses React.createElement
|
|
33
|
+
* @default 'automatic'
|
|
34
|
+
*/
|
|
35
|
+
jsxRuntime?: 'automatic' | 'classic';
|
|
36
|
+
/**
|
|
37
|
+
* The source for JSX imports when using the automatic runtime.
|
|
38
|
+
* @default 'react'
|
|
39
|
+
* @example 'nativewind' for NativeWind v4+
|
|
40
|
+
*/
|
|
41
|
+
jsxImportSource?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Modules that should not be tree-shaken.
|
|
44
|
+
* Some React Native packages have side effects that may be incorrectly removed.
|
|
45
|
+
* @default ['react-native-css-interop', 'expo-modules-core']
|
|
46
|
+
*/
|
|
47
|
+
noTreeshakeModules?: string[];
|
|
48
|
+
/**
|
|
49
|
+
* Absolute path to the react-native-web package directory.
|
|
50
|
+
* This is needed for pnpm/monorepo setups where react-native-reanimated
|
|
51
|
+
* cannot resolve react-native-web internal modules.
|
|
52
|
+
*
|
|
53
|
+
* If provided, the plugin will rewrite import paths in transformed code
|
|
54
|
+
* to use absolute paths, ensuring proper module resolution.
|
|
55
|
+
*
|
|
56
|
+
* @example '/path/to/node_modules/react-native-web'
|
|
57
|
+
*/
|
|
58
|
+
reactNativeWebPath?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Code transformation utilities for fixing React Native package compatibility issues
|
|
63
|
+
* Ported from vite-plugin-rnw (https://github.com/dannyhw/vite-plugin-rnw)
|
|
64
|
+
*/
|
|
65
|
+
export declare interface TransformResult {
|
|
66
|
+
code: string;
|
|
67
|
+
map: string | null;
|
|
68
|
+
changed: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,228 +1,248 @@
|
|
|
1
|
-
import
|
|
2
|
-
import CJS_COMPAT_NODE_PATH_25fbad5c92e2ff5b from 'node:path';
|
|
3
|
-
import CJS_COMPAT_NODE_MODULE_25fbad5c92e2ff5b from "node:module";
|
|
4
|
-
|
|
5
|
-
var __filename = CJS_COMPAT_NODE_URL_25fbad5c92e2ff5b.fileURLToPath(import.meta.url);
|
|
6
|
-
var __dirname = CJS_COMPAT_NODE_PATH_25fbad5c92e2ff5b.dirname(__filename);
|
|
7
|
-
var require = CJS_COMPAT_NODE_MODULE_25fbad5c92e2ff5b.createRequire(import.meta.url);
|
|
8
|
-
|
|
9
|
-
// ------------------------------------------------------------
|
|
10
|
-
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
-
// ------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
// src/index.ts
|
|
14
|
-
import { normalize as normalize2 } from "pathe";
|
|
15
|
-
|
|
16
|
-
// src/transforms.ts
|
|
17
|
-
import MagicString from "magic-string";
|
|
1
|
+
import "node:module";
|
|
18
2
|
import { normalize } from "pathe";
|
|
3
|
+
import magic_string from "magic-string";
|
|
19
4
|
function analyzeRequireStatements(originalCode, exportedVars) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
const importMap = new Map();
|
|
6
|
+
for (const varName of exportedVars){
|
|
7
|
+
const requirePattern = new RegExp(`${varName}\\s*=\\s*[\\s\\S]*?require\\(['"]([^'"]+)['"]\\)(?:\\.([\\w]+))?`, 'g');
|
|
8
|
+
const requireMatch = requirePattern.exec(originalCode);
|
|
9
|
+
if (requireMatch) {
|
|
10
|
+
const [, modulePath, prop] = requireMatch;
|
|
11
|
+
const key = `${modulePath}:${prop || 'default'}`;
|
|
12
|
+
if (!importMap.has(key)) importMap.set(key, []);
|
|
13
|
+
importMap.get(key).push(varName);
|
|
14
|
+
}
|
|
29
15
|
}
|
|
30
|
-
|
|
31
|
-
return importMap;
|
|
16
|
+
return importMap;
|
|
32
17
|
}
|
|
33
18
|
function generateDirectExports(importMap, resolveModule) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
exports += `export {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
for (let varName of vars)
|
|
43
|
-
exports += `export { ${prop} as ${varName} } from '${resolvedPath}';
|
|
44
|
-
`;
|
|
45
|
-
}
|
|
46
|
-
return exports;
|
|
19
|
+
let exports = '';
|
|
20
|
+
for (const [key, vars] of importMap){
|
|
21
|
+
const [modulePath, prop] = key.split(':');
|
|
22
|
+
const resolvedPath = resolveModule ? resolveModule(modulePath) : modulePath;
|
|
23
|
+
if ('default' === prop) for (const varName of vars)exports += `export { default as ${varName} } from '${resolvedPath}';\n`;
|
|
24
|
+
else for (const varName of vars)exports += `export { ${prop} as ${varName} } from '${resolvedPath}';\n`;
|
|
25
|
+
}
|
|
26
|
+
return exports;
|
|
47
27
|
}
|
|
48
28
|
function transformReanimatedWebUtils(code, id, _isProduction, opts) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
ms
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
29
|
+
const normalizedId = normalize(id);
|
|
30
|
+
const reanimatedInNodeModules = normalizedId.includes('react-native-reanimated') && normalizedId.includes('node_modules');
|
|
31
|
+
if (!reanimatedInNodeModules || !normalizedId.includes('ReanimatedModule/js-reanimated/webUtils') || !code.includes('export let') || !code.includes('try') || !code.includes('require')) return {
|
|
32
|
+
code,
|
|
33
|
+
map: null,
|
|
34
|
+
changed: false
|
|
35
|
+
};
|
|
36
|
+
const exportLetMatches = Array.from(code.matchAll(/export let (\w+);/g));
|
|
37
|
+
const exportedVars = exportLetMatches.map((match)=>match[1]);
|
|
38
|
+
if (0 === exportedVars.length) return {
|
|
39
|
+
code,
|
|
40
|
+
map: null,
|
|
41
|
+
changed: false
|
|
42
|
+
};
|
|
43
|
+
const importMap = analyzeRequireStatements(code, exportedVars);
|
|
44
|
+
const ms = new magic_string(code);
|
|
45
|
+
let changed = false;
|
|
46
|
+
for (const m of code.matchAll(/try\s*\{[^{}]*?require\([^)]+\)[^{}]*?\}\s*catch[^{}]*?\{[^{}]*?\}/gs)){
|
|
47
|
+
const start = m.index;
|
|
48
|
+
const end = start + m[0].length;
|
|
49
|
+
ms.remove(start, end);
|
|
50
|
+
changed = true;
|
|
51
|
+
}
|
|
52
|
+
for (const m of code.matchAll(/export let \w+;/g)){
|
|
53
|
+
const start = m.index;
|
|
54
|
+
const end = start + m[0].length;
|
|
55
|
+
ms.remove(start, end);
|
|
56
|
+
changed = true;
|
|
57
|
+
}
|
|
58
|
+
const exports = generateDirectExports(importMap, opts?.resolveModule);
|
|
59
|
+
if (exports) {
|
|
60
|
+
ms.append(`\n${exports}`);
|
|
61
|
+
changed = true;
|
|
62
|
+
}
|
|
63
|
+
if (!changed) return {
|
|
64
|
+
code,
|
|
65
|
+
map: null,
|
|
66
|
+
changed: false
|
|
67
|
+
};
|
|
68
|
+
const resultCode = ms.toString();
|
|
69
|
+
const map = ms.generateMap({
|
|
70
|
+
source: opts?.source ?? id.split('?')[0],
|
|
71
|
+
includeContent: true,
|
|
72
|
+
hires: true
|
|
73
|
+
}).toString();
|
|
74
|
+
return {
|
|
75
|
+
code: resultCode,
|
|
76
|
+
map,
|
|
77
|
+
changed: true
|
|
78
|
+
};
|
|
76
79
|
}
|
|
77
80
|
function transformCssInteropDoctorCheck(code, id, opts) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
81
|
+
const normalizedId = normalize(id);
|
|
82
|
+
const isTargetFile = normalizedId.includes('node_modules/react-native-css-interop/dist/doctor.js');
|
|
83
|
+
if (!isTargetFile) return {
|
|
84
|
+
code,
|
|
85
|
+
map: null,
|
|
86
|
+
changed: false
|
|
87
|
+
};
|
|
88
|
+
const pattern = /return\s*<react-native-css-interop-jsx-pragma-check\s*\/>\s*===\s*true\s*;/g;
|
|
89
|
+
if (!pattern.test(code)) return {
|
|
90
|
+
code,
|
|
91
|
+
map: null,
|
|
92
|
+
changed: false
|
|
93
|
+
};
|
|
94
|
+
const ms = new magic_string(code);
|
|
95
|
+
let match;
|
|
96
|
+
pattern.lastIndex = 0;
|
|
97
|
+
while(null !== (match = pattern.exec(code))){
|
|
98
|
+
const start = match.index;
|
|
99
|
+
const end = start + match[0].length;
|
|
100
|
+
ms.overwrite(start, end, 'return true;');
|
|
101
|
+
}
|
|
102
|
+
const resultCode = ms.toString();
|
|
103
|
+
const map = ms.generateMap({
|
|
104
|
+
source: opts?.source ?? id.split('?')[0],
|
|
105
|
+
includeContent: true,
|
|
106
|
+
hires: true
|
|
107
|
+
}).toString();
|
|
108
|
+
return {
|
|
109
|
+
code: resultCode,
|
|
110
|
+
map,
|
|
111
|
+
changed: true
|
|
112
|
+
};
|
|
96
113
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
114
|
+
const webExtensions = [
|
|
115
|
+
'.web.mjs',
|
|
116
|
+
'.web.js',
|
|
117
|
+
'.web.jsx',
|
|
118
|
+
'.web.ts',
|
|
119
|
+
'.web.tsx',
|
|
120
|
+
'.mjs',
|
|
121
|
+
'.js',
|
|
122
|
+
'.jsx',
|
|
123
|
+
'.ts',
|
|
124
|
+
'.tsx',
|
|
125
|
+
'.json'
|
|
126
|
+
];
|
|
127
|
+
const DEFAULT_MODULES_TO_TRANSPILE = [
|
|
128
|
+
'react-native',
|
|
129
|
+
'@react-native',
|
|
130
|
+
'expo',
|
|
131
|
+
'@expo'
|
|
132
|
+
];
|
|
133
|
+
const DEFAULT_NO_TREESHAKE_MODULES = [
|
|
134
|
+
'react-native-css-interop',
|
|
135
|
+
'react-native-css',
|
|
136
|
+
'expo-modules-core'
|
|
120
137
|
];
|
|
121
138
|
function createTranspileIncludePattern(modules) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
);
|
|
125
|
-
return new RegExp(`node_modules[\\\\/](${escapedModules.join("|")})`);
|
|
139
|
+
const escapedModules = modules.map((m)=>m.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
140
|
+
return new RegExp(`node_modules[\\\\/](${escapedModules.join('|')})`);
|
|
126
141
|
}
|
|
127
142
|
function pluginReactNativeWeb(options = {}) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
name: "rsbuild:react-native-web",
|
|
153
|
-
setup(api) {
|
|
154
|
-
let isProduction = !1;
|
|
155
|
-
api.modifyRsbuildConfig((config) => (config.source ??= {}, config.source.define = {
|
|
156
|
-
...config.source.define,
|
|
157
|
-
__DEV__: JSON.stringify(process.env.NODE_ENV !== "production"),
|
|
158
|
-
"process.env.NODE_ENV": JSON.stringify(
|
|
159
|
-
process.env.NODE_ENV || "development"
|
|
160
|
-
),
|
|
161
|
-
EXPO_OS: JSON.stringify("web"),
|
|
162
|
-
"process.env.EXPO_OS": JSON.stringify("web"),
|
|
163
|
-
_WORKLET: "false",
|
|
164
|
-
_frameTimestamp: "undefined",
|
|
165
|
-
"global.Error": "Error",
|
|
166
|
-
"global.__x": "{}"
|
|
167
|
-
}, config.resolve ??= {}, config.resolve.extensions = webExtensions, config.source.include = [
|
|
168
|
-
...config.source.include || [],
|
|
169
|
-
includePattern
|
|
170
|
-
], config)), api.onBeforeCreateCompiler(() => {
|
|
171
|
-
isProduction = api.context.bundlerType === "rspack" ? process.env.NODE_ENV === "production" : !1;
|
|
172
|
-
}), api.modifyBundlerChain((chain) => {
|
|
173
|
-
let jsRule = chain.module.rule("js");
|
|
174
|
-
jsRule && jsRule.include.add(includePattern);
|
|
175
|
-
let reactConfig = {
|
|
176
|
-
runtime: jsxRuntime
|
|
177
|
-
};
|
|
178
|
-
jsxImportSource && jsxRuntime === "automatic" && (reactConfig.importSource = jsxImportSource), chain.module.rule("react-native-jsx").test(/\.(js|mjs|jsx)$/).include.add(includePattern).end().use("swc").loader("builtin:swc-loader").options({
|
|
179
|
-
jsc: {
|
|
180
|
-
parser: {
|
|
181
|
-
syntax: "ecmascript",
|
|
182
|
-
jsx: !0
|
|
183
|
-
},
|
|
184
|
-
transform: {
|
|
185
|
-
react: reactConfig
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}), chain.module.rule("react-native-no-treeshake").test(/\.(js|mjs|jsx|ts|tsx)$/).include.add(noTreeshakePattern).end().set("sideEffects", !0);
|
|
189
|
-
});
|
|
190
|
-
let moduleResolver = createModuleResolver();
|
|
191
|
-
api.transform(
|
|
192
|
-
{
|
|
193
|
-
test: /\.(js|mjs|jsx|ts|tsx)$/
|
|
194
|
-
},
|
|
195
|
-
({ code, resource }) => {
|
|
196
|
-
let cssInteropResult = transformCssInteropDoctorCheck(
|
|
197
|
-
code,
|
|
198
|
-
resource,
|
|
199
|
-
{
|
|
200
|
-
source: resource
|
|
143
|
+
const modulesToTranspile = [
|
|
144
|
+
...new Set([
|
|
145
|
+
...DEFAULT_MODULES_TO_TRANSPILE,
|
|
146
|
+
...options.modulesToTranspile || []
|
|
147
|
+
])
|
|
148
|
+
];
|
|
149
|
+
const includePattern = createTranspileIncludePattern(modulesToTranspile);
|
|
150
|
+
const jsxRuntime = options.jsxRuntime ?? 'automatic';
|
|
151
|
+
const jsxImportSource = options.jsxImportSource;
|
|
152
|
+
const noTreeshakeModules = [
|
|
153
|
+
...new Set([
|
|
154
|
+
...DEFAULT_NO_TREESHAKE_MODULES,
|
|
155
|
+
...options.noTreeshakeModules || []
|
|
156
|
+
])
|
|
157
|
+
];
|
|
158
|
+
const noTreeshakePattern = createTranspileIncludePattern(noTreeshakeModules);
|
|
159
|
+
const reactNativeWebPath = options.reactNativeWebPath;
|
|
160
|
+
function createModuleResolver() {
|
|
161
|
+
if (!reactNativeWebPath) return;
|
|
162
|
+
const normalizedReactNativeWebPath = normalize(reactNativeWebPath);
|
|
163
|
+
return (modulePath)=>{
|
|
164
|
+
if (modulePath.startsWith('react-native-web/')) {
|
|
165
|
+
const relativePart = modulePath.slice(17);
|
|
166
|
+
return `${normalizedReactNativeWebPath}/${relativePart}`;
|
|
201
167
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return {
|
|
205
|
-
code: cssInteropResult.code,
|
|
206
|
-
map: cssInteropResult.map ?? void 0
|
|
207
|
-
};
|
|
208
|
-
let reanimatedResult = transformReanimatedWebUtils(
|
|
209
|
-
code,
|
|
210
|
-
resource,
|
|
211
|
-
isProduction,
|
|
212
|
-
{
|
|
213
|
-
source: resource,
|
|
214
|
-
resolveModule: moduleResolver
|
|
215
|
-
}
|
|
216
|
-
);
|
|
217
|
-
return reanimatedResult.changed ? {
|
|
218
|
-
code: reanimatedResult.code,
|
|
219
|
-
map: reanimatedResult.map ?? void 0
|
|
220
|
-
} : { code };
|
|
221
|
-
}
|
|
222
|
-
);
|
|
168
|
+
return modulePath;
|
|
169
|
+
};
|
|
223
170
|
}
|
|
224
|
-
|
|
171
|
+
return {
|
|
172
|
+
name: 'rsbuild:react-native-web',
|
|
173
|
+
setup (api) {
|
|
174
|
+
let isProduction = false;
|
|
175
|
+
api.modifyRsbuildConfig((config)=>{
|
|
176
|
+
config.source ??= {};
|
|
177
|
+
const isDevelopment = options.dev ?? 'production' !== process.env.NODE_ENV;
|
|
178
|
+
const nodeEnvDefine = null != options.dev ? JSON.stringify(isDevelopment ? 'development' : 'production') : config.source.define?.['process.env.NODE_ENV'] ?? JSON.stringify(process.env.NODE_ENV || 'development');
|
|
179
|
+
const devDefine = null != options.dev ? JSON.stringify(options.dev) : config.source.define?.__DEV__ ?? JSON.stringify(isDevelopment);
|
|
180
|
+
config.source.define = {
|
|
181
|
+
...config.source.define,
|
|
182
|
+
__DEV__: devDefine,
|
|
183
|
+
'process.env.NODE_ENV': nodeEnvDefine,
|
|
184
|
+
EXPO_OS: JSON.stringify('web'),
|
|
185
|
+
'process.env.EXPO_OS': JSON.stringify('web'),
|
|
186
|
+
_WORKLET: 'false',
|
|
187
|
+
_frameTimestamp: 'undefined',
|
|
188
|
+
'global.Error': 'Error',
|
|
189
|
+
'global.__x': '{}'
|
|
190
|
+
};
|
|
191
|
+
config.resolve ??= {};
|
|
192
|
+
config.resolve.extensions = webExtensions;
|
|
193
|
+
config.source.include = [
|
|
194
|
+
...config.source.include || [],
|
|
195
|
+
includePattern
|
|
196
|
+
];
|
|
197
|
+
return config;
|
|
198
|
+
});
|
|
199
|
+
api.onBeforeCreateCompiler(()=>{
|
|
200
|
+
isProduction = 'rspack' === api.context.bundlerType ? 'production' === process.env.NODE_ENV : false;
|
|
201
|
+
});
|
|
202
|
+
api.modifyBundlerChain((chain)=>{
|
|
203
|
+
const jsRule = chain.module.rule('js');
|
|
204
|
+
if (jsRule) jsRule.include.add(includePattern);
|
|
205
|
+
const reactConfig = {
|
|
206
|
+
runtime: jsxRuntime
|
|
207
|
+
};
|
|
208
|
+
if (jsxImportSource && 'automatic' === jsxRuntime) reactConfig.importSource = jsxImportSource;
|
|
209
|
+
chain.module.rule('react-native-jsx').test(/\.(js|mjs|jsx)$/).include.add(includePattern).end().use('swc').loader('builtin:swc-loader').options({
|
|
210
|
+
jsc: {
|
|
211
|
+
parser: {
|
|
212
|
+
syntax: "ecmascript",
|
|
213
|
+
jsx: true
|
|
214
|
+
},
|
|
215
|
+
transform: {
|
|
216
|
+
react: reactConfig
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
chain.module.rule('react-native-no-treeshake').test(/\.(js|mjs|jsx|ts|tsx)$/).include.add(noTreeshakePattern).end().set('sideEffects', true);
|
|
221
|
+
});
|
|
222
|
+
const moduleResolver = createModuleResolver();
|
|
223
|
+
api.transform({
|
|
224
|
+
test: /\.(js|mjs|jsx|ts|tsx)$/
|
|
225
|
+
}, ({ code, resource })=>{
|
|
226
|
+
const cssInteropResult = transformCssInteropDoctorCheck(code, resource, {
|
|
227
|
+
source: resource
|
|
228
|
+
});
|
|
229
|
+
if (cssInteropResult.changed) return {
|
|
230
|
+
code: cssInteropResult.code,
|
|
231
|
+
map: cssInteropResult.map ?? void 0
|
|
232
|
+
};
|
|
233
|
+
const reanimatedResult = transformReanimatedWebUtils(code, resource, isProduction, {
|
|
234
|
+
source: resource,
|
|
235
|
+
resolveModule: moduleResolver
|
|
236
|
+
});
|
|
237
|
+
if (reanimatedResult.changed) return {
|
|
238
|
+
code: reanimatedResult.code,
|
|
239
|
+
map: reanimatedResult.map ?? void 0
|
|
240
|
+
};
|
|
241
|
+
return {
|
|
242
|
+
code
|
|
243
|
+
};
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
};
|
|
225
247
|
}
|
|
226
|
-
export {
|
|
227
|
-
pluginReactNativeWeb
|
|
228
|
-
};
|
|
248
|
+
export { pluginReactNativeWeb };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rsbuild-plugin-react-native-web",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "Rsbuild plugin for React Native Web support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rsbuild",
|
|
@@ -35,11 +35,12 @@
|
|
|
35
35
|
"!src/**/*"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"magic-string": "^
|
|
38
|
+
"magic-string": "^1.4.1",
|
|
39
39
|
"pathe": "^2.0.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@
|
|
42
|
+
"@microsoft/api-extractor": "^7.59.1",
|
|
43
|
+
"@rsbuild/core": "^2.2.6",
|
|
43
44
|
"@types/node": "^22.0.0",
|
|
44
45
|
"typescript": "^5.9.3"
|
|
45
46
|
},
|
|
@@ -59,8 +60,7 @@
|
|
|
59
60
|
"platform": "node"
|
|
60
61
|
},
|
|
61
62
|
"scripts": {
|
|
62
|
-
"build": "
|
|
63
|
-
"
|
|
64
|
-
"prep": "jiti ../../scripts/build/build-package.ts"
|
|
63
|
+
"build": "rstack lib",
|
|
64
|
+
"dev": "rstack lib --watch"
|
|
65
65
|
}
|
|
66
66
|
}
|