Skip to content

Commit b9368d2

Browse files
author
徐远翔
committed
feat: support mutiply bundlers: react-native-cli, haul, expo
1 parent c6bd193 commit b9368d2

File tree

28 files changed

+388
-512
lines changed

28 files changed

+388
-512
lines changed

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
*.woff2 binary
88
*.jar binary
99
*.pbxproj -text
10-
10+
*.ttf binary
Binary file not shown.
Binary file not shown.

example/ios/RNUMITestApp.xcodeproj/project.pbxproj

+17
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
591F4E3659397AE1C0A4F4C0 /* libPods-RNUMITestApp-RNUMITestAppTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 70E1EACDA399EB87AEAC6136 /* libPods-RNUMITestApp-RNUMITestAppTests.a */; };
2121
A2FAA3AC8AE4043AA37BB78F /* libPods-RNUMITestApp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 99559606A31FEC53CE934C6F /* libPods-RNUMITestApp.a */; };
2222
F9A2961D1159DB8736548177 /* libPods-RNUMITestApp-tvOSTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BE7C092CE90A19B02CC6652E /* libPods-RNUMITestApp-tvOSTests.a */; };
23+
70896E68FBED41819E68AC24 /* antfill.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 9A82B98A56B7419F872753FF /* antfill.ttf */; };
24+
FE52E9DBDE9E43B0B4D1299C /* antoutline.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 7B8A42DD87F3415FAC2708E1 /* antoutline.ttf */; };
2325
/* End PBXBuildFile section */
2426

2527
/* Begin PBXContainerItemProxy section */
@@ -67,6 +69,8 @@
6769
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
6870
ED2971642150620600B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS12.0.sdk/System/Library/Frameworks/JavaScriptCore.framework; sourceTree = DEVELOPER_DIR; };
6971
F7023ABB92180D3187159891 /* Pods-RNUMITestApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNUMITestApp.debug.xcconfig"; path = "Target Support Files/Pods-RNUMITestApp/Pods-RNUMITestApp.debug.xcconfig"; sourceTree = "<group>"; };
72+
9A82B98A56B7419F872753FF /* antfill.ttf */ = {isa = PBXFileReference; name = "antfill.ttf"; path = "../node_modules/@ant-design/icons-react-native/fonts/antfill.ttf"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = unknown; explicitFileType = undefined; includeInIndex = 0; };
73+
7B8A42DD87F3415FAC2708E1 /* antoutline.ttf */ = {isa = PBXFileReference; name = "antoutline.ttf"; path = "../node_modules/@ant-design/icons-react-native/fonts/antoutline.ttf"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = unknown; explicitFileType = undefined; includeInIndex = 0; };
7074
/* End PBXFileReference section */
7175

7276
/* Begin PBXFrameworksBuildPhase section */
@@ -165,6 +169,7 @@
165169
83CBBA001A601CBA00E9B192 /* Products */,
166170
2D16E6871FA4F8E400B85C8A /* Frameworks */,
167171
9FB6EF2DD427E82299032FCA /* Pods */,
172+
E431C99AD19A44568EBBE2D3 /* Resources */,
168173
);
169174
indentWidth = 2;
170175
sourceTree = "<group>";
@@ -198,6 +203,16 @@
198203
path = Pods;
199204
sourceTree = "<group>";
200205
};
206+
E431C99AD19A44568EBBE2D3 /* Resources */ = {
207+
isa = "PBXGroup";
208+
children = (
209+
9A82B98A56B7419F872753FF /* antfill.ttf */,
210+
7B8A42DD87F3415FAC2708E1 /* antoutline.ttf */,
211+
);
212+
name = Resources;
213+
sourceTree = "<group>";
214+
path = "";
215+
};
201216
/* End PBXGroup section */
202217

203218
/* Begin PBXNativeTarget section */
@@ -340,6 +355,8 @@
340355
files = (
341356
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
342357
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
358+
70896E68FBED41819E68AC24 /* antfill.ttf in Resources */,
359+
FE52E9DBDE9E43B0B4D1299C /* antoutline.ttf in Resources */,
343360
);
344361
runOnlyForDeploymentPostprocessing = 0;
345362
};

example/ios/RNUMITestApp/Info.plist

+6-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</dict>
3939
</dict>
4040
<key>NSLocationWhenInUseUsageDescription</key>
41-
<string></string>
41+
<string/>
4242
<key>UILaunchStoryboardName</key>
4343
<string>LaunchScreen</string>
4444
<key>UIRequiredDeviceCapabilities</key>
@@ -53,5 +53,10 @@
5353
</array>
5454
<key>UIViewControllerBasedStatusBarAppearance</key>
5555
<false/>
56+
<key>UIAppFonts</key>
57+
<array>
58+
<string>antfill.ttf</string>
59+
<string>antoutline.ttf</string>
60+
</array>
5661
</dict>
5762
</plist>

example/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"scripts": {
66
"android": "react-native run-android",
77
"ios": "react-native run-ios",
8+
"watch": "umi g rn --dev",
89
"start": "react-native start",
910
"test": "jest"
1011
},

example/pages/home.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import { View, Text } from 'react-native';
3+
4+
function HomePage() {
5+
return (
6+
<View>
7+
<Text>Home Screen</Text>
8+
</View>
9+
);
10+
}
11+
12+
HomePage.title = 'Home Page';
13+
14+
export default HomePage;

example/pages/login.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import { View, Text } from 'react-native';
3+
4+
function LoginPage() {
5+
return (
6+
<View>
7+
<Text>Login Screen</Text>
8+
</View>
9+
);
10+
}
11+
12+
LoginPage.title = 'Login Page';
13+
14+
export default LoginPage;

packages/umi-preset-react-native/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
},
5050
"dependencies": {
5151
"@types/react-router-native": "5.1.0",
52-
"babel-plugin-module-resolver": "^4.0.0",
53-
"memoizerific": "^1.11.3",
52+
"babel-plugin-module-resolver": "4.0.0",
53+
"memoizerific": "1.11.3",
5454
"react-router-native": "5.1.2"
5555
}
5656
}

packages/umi-preset-react-native/src/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
export default function () {
22
return {
33
plugins: [
4-
require.resolve('./plugins/commands/reactNative'),
54
require.resolve('./plugins/features/reactNative'),
65
require.resolve('./plugins/generateFiles/react-native/exports'),
7-
// require.resolve('./plugins/generateFiles/react-native/haulConfig'),
86
require.resolve('./plugins/generateFiles/react-native/polyfill'),
97
require.resolve('./plugins/generateFiles/react-native/routes'),
108
require.resolve('./plugins/generateFiles/react-native/runtime'),

packages/umi-preset-react-native/src/plugins/commands/reactNative.ts

-28
This file was deleted.

packages/umi-preset-react-native/src/plugins/commands/subs/bundle.ts

-65
This file was deleted.

packages/umi-preset-react-native/src/plugins/commands/subs/shared.ts

-18
This file was deleted.

packages/umi-preset-react-native/src/plugins/commands/subs/start.ts

-60
This file was deleted.

packages/umi-preset-react-native/src/plugins/features/reactNative.ts

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IApi } from 'umi';
22
import { dirname, join } from 'path';
3-
import { readFileSync } from 'fs';
3+
import { existsSync, readFileSync } from 'fs';
44
import { EOL } from 'os';
55
import { assertExists } from '../../utils';
66

@@ -36,29 +36,36 @@ export default (api: IApi) => {
3636
join(absNodeModulesPath, 'react-native'),
3737
true,
3838
);
39-
39+
const EXPO_PATH = getUserLibDir(join('expo', 'package.json'), join(absNodeModulesPath, 'expo'));
40+
const HAUL_CLI_PATH = getUserLibDir(join('@haul-bundler', 'cli', 'package.json'), join(absNodeModulesPath, 'expo'));
4041
assertExists(REACT_NATIVE_PATH);
4142

43+
const isExpo = existsSync(EXPO_PATH);
44+
const isHaul = existsSync(HAUL_CLI_PATH);
45+
4246
const { version } = require(join(REACT_NATIVE_PATH, 'package.json'));
4347

4448
let appKey;
4549
try {
46-
const appJson = JSON.parse(
47-
readFileSync(getUserLibDir('app.json', join(absSrcPath, 'app.json'), false, absSrcPath), 'utf8'),
48-
);
49-
appKey = appJson.name;
50+
if (!isExpo) {
51+
const appJson = JSON.parse(
52+
readFileSync(getUserLibDir('app.json', join(absSrcPath, 'app.json'), false, absSrcPath), 'utf8'),
53+
);
54+
appKey = appJson.name;
55+
}
5056
} catch (ignored) {}
5157

5258
// umi-preset-react-native 扩展配置
5359
api.describe({
5460
key: 'reactNative',
5561
config: {
56-
default: { appKey, version },
62+
default: { appKey, version, bundler: isExpo ? 'expo' : isHaul ? 'haul' : 'react-native-cli' },
5763
schema(joi) {
5864
return joi
5965
.object({
6066
appKey: joi.string(), // moduleName app.json#name
6167
version: joi.string(), // RN 版本号
68+
bundler: joi.allow('expo', 'react-native-cli', 'haul'),
6269
})
6370
.optional();
6471
},
@@ -79,8 +86,6 @@ export default (api: IApi) => {
7986
config.history,
8087
);
8188

82-
config.extraBabelPresets = ['module:metro-react-native-babel-preset'];
83-
8489
return config;
8590
});
8691

@@ -102,15 +107,17 @@ export default (api: IApi) => {
102107

103108
// 启动时检查
104109
api.onStart(() => {
105-
// appKey 一定不能为空,否则 RN 引用没法注册/部署/启动。
106-
if (!api.config?.reactNative?.appKey) {
107-
api.logger
108-
.error(`"reactNative.appKey" 未配置!${EOL}1. 请在工程根目录下的 app.json 文件中为"name"字段指定一个值,作为"appKey";${EOL}2. 也可以在 umi 配置文件(比如:.umirc.js)中设置:${EOL}export default {
110+
if (!isExpo) {
111+
// 使用 haul 和 react-native-cli 时,appKey 一定不能为空,否则 RN 引用没法注册/部署/启动。
112+
if (!api.config?.reactNative?.appKey) {
113+
api.logger
114+
.error(`"reactNative.appKey" 未配置!${EOL}1. 请在工程根目录下的 app.json 文件中为"name"字段指定一个值,作为"appKey";${EOL}2. 也可以在 umi 配置文件(比如:.umirc.js)中设置:${EOL}export default {
109115
reactNative: {
110116
appKey: '将这里替换为你的值',
111117
},
112118
};。${EOL}小贴士:${EOL} "appKey" 即 RN JS 代码域中: "AppRegistry.registerComponent(appKey, componentProvider);"的第一个参数,也是 iOS/Android 原生代码中加载 bundle 时所需的 "moduleName";${EOL} 其值是使用 react-native 命令行工具初始化新建 RN 工程时所指定的项目名称,存储在工程根目录下 app.json 文件的 "name" 字段中。`);
113-
throw new TypeError('"react-native.appKey" 未配置');
119+
throw new TypeError('"react-native.appKey" 未配置');
120+
}
114121
}
115122

116123
// mountElementId 必须为空字符串,false也不行。

0 commit comments

Comments
 (0)