10
10
| NPM 包 | 当前版本 | 简介 |
11
11
| --- | --- | --- |
12
12
| [ umi-plugin-antd-react-native] ( packages/umi-plugin-antd-react-native ) | [ ![ npm version] ( https://img.shields.io/npm/v/umi-plugin-antd-react-native.svg?style=flat-square )] ( https://www.npmjs.com/package/umi-plugin-antd-react-native ) | 针对[ @ant-design/react-native ] ( https://rn.mobile.ant.design/index-cn ) 的[ umi] ( https://umijs.org/ ) 插件,为其提供按需加载,主题/皮肤定制、预设、切换,国际化等支持。 |
13
- | [ umi-preset-react-native] ( packages/umi-preset-react-native ) | [ ![ npm version] ( https://img.shields.io/npm/v/umi-preset-react-native.svg?style=flat-square )] ( https://www.npmjs.com/package/umi-preset-react-native ) | 针对 [ react-native ] ( https://reactnative.dev/ ) 应用的 [ umi] ( https://umijs.org/ ) 插件集,为其提供 开发、编译、打包的支持。 需要 [ react-native] ( https://reactnative.dev/ ) ** 0.59 .0 及以上版本(>=0.59 .0)** |
14
- | [ umi-preset-react-navigation] ( packages/umi-preset-react-navigation ) | [ ![ npm version] ( https://img.shields.io/npm/v/umi-preset-react-navigation.svg?style=flat-square )] ( https://www.npmjs.com/package/umi-preset-react-navigation ) | 针对 [ react-navigation] ( https://reactnavigation.org/ ) 的插件集,替换 [ umi] ( https://umijs.org/ ) 内置的 [ react-router] ( https://reacttraining.com/react-router/ ) ,开发地道的原生应用。需要 [ react-native] ( https://reactnative.dev/ ) ** 0.60.0 及以上版本(>=0.60.0)** |
13
+ | [ umi-preset-react-native] ( packages/umi-preset-react-native ) | [ ![ npm version] ( https://img.shields.io/npm/v/umi-preset-react-native.svg?style=flat-square )] ( https://www.npmjs.com/package/umi-preset-react-native ) | 基础包,让 [ umi] ( https://umijs.org/ ) 具备开发 RN 的能力。 ** 需要 [ react-native] ( https://reactnative.dev/ ) 0.44 .0 及以上版本(>=0.44 .0)** |
14
+ | [ umi-preset-react-navigation] ( packages/umi-preset-react-navigation ) | [ ![ npm version] ( https://img.shields.io/npm/v/umi-preset-react-navigation.svg?style=flat-square )] ( https://www.npmjs.com/package/umi-preset-react-navigation ) | 针对 [ react-navigation] ( https://reactnavigation.org/ ) 的插件集,替换 [ umi] ( https://umijs.org/ ) 内置的 [ react-router] ( https://reacttraining.com/react-router/ ) ,开发地道的原生应用。** 需要 [ react-native] ( https://reactnative.dev/ ) 0.60.0 及以上版本(>=0.60.0)** |
15
15
16
16
[ 发布日志] ( /CHANGELOG.md )
17
17
26
26
- [ 集成 react-navigation(可选)] ( #%E9%9B%86%E6%88%90-react-navigation%E5%8F%AF%E9%80%89 )
27
27
- [ 配置] ( #%E9%85%8D%E7%BD%AE )
28
28
- [ 目前支持的 umi 配置项] ( #%E7%9B%AE%E5%89%8D%E6%94%AF%E6%8C%81%E7%9A%84-umi-%E9%85%8D%E7%BD%AE%E9%A1%B9 )
29
- - [ umi-preset-react-native 扩展配置] ( #umi-preset-react-native-%E6%89%A9%E5%B1%95%E9%85%8D%E7%BD%AE )
30
29
- [ 使用] ( #%E4%BD%BF%E7%94%A8 )
31
30
- [ 开发] ( #%E5%BC%80%E5%8F%91 )
32
31
- [ 打包] ( #%E6%89%93%E5%8C%85 )
36
35
- [ 没有` NavLink ` 组件] ( #%E6%B2%A1%E6%9C%89navlink%E7%BB%84%E4%BB%B6 )
37
36
- [ 新增` BackButton ` 和` AndroidBackButton ` 组件] ( #%E6%96%B0%E5%A2%9Ebackbutton%E5%92%8Candroidbackbutton%E7%BB%84%E4%BB%B6 )
38
37
- [ 使用 react-navigation] ( #%E4%BD%BF%E7%94%A8-react-navigation )
39
- - [ 深入] ( #%E6%B7%B1%E5%85%A5 )
40
- - [ 切分多 bundle] ( #%E5%88%87%E5%88%86%E5%A4%9A-bundle )
41
38
- [ FAQ] ( #faq )
42
39
- [ hmrClient.send is not a function] ( #hmrclientsend-is-not-a-function )
43
- - [ Live Reloading, Fast Refresh, Hot Replacement... 无法使用] ( #live-reloading-fast-refresh-hot-replacement-%E6%97%A0%E6%B3%95%E4%BD%BF%E7%94%A8 )
44
40
- [ 使用 @ant-design/react-native 组件时,报错:Unrecognized font family 'antoutline'] ( #%E4%BD%BF%E7%94%A8-ant-designreact-native-%E7%BB%84%E4%BB%B6%E6%97%B6%E6%8A%A5%E9%94%99unrecognized-font-family-antoutline )
45
41
46
42
## 必备
47
43
48
44
- RN 工程(已有,或使用` react-native init ` 新建);
49
45
- 全局 或 RN 工程本地(内部)安装 umi 3.0 及以上版本。
50
46
51
- Node、react、react-native、umi 版本要求:
52
-
53
- ``` json
54
- {
55
- "name" : " umi-preset-react-native" ,
56
- "engines" : {
57
- "node" : " >=10.x"
58
- },
59
- "peerDependencies" : {
60
- "react" : " ^16.8.3" ,
61
- "react-native" : " >=0.59.0 <1.0.x" ,
62
- "umi" : " ^3.0.0"
63
- }
64
- }
65
- ```
66
-
67
47
## 安装
68
48
69
49
如果没有 RN 工程,则使用` react-native init ` 得到初始工程:
@@ -168,13 +148,11 @@ _与 DOM 无关的[umi](https://umijs.org/)插件都是可以使用的,或者
168
148
169
149
### 目前支持的 umi 配置项
170
150
171
- ** umi-preset-react-native** 使用[ haul ] ( https://github.com/callstack/haul ) 打包器。
151
+ ** umi-preset-react-native** 使用 RN 官方的 [ metro ] ( https://github.com/facebook/metro ) 打包器。
172
152
173
153
目前支持的 umi 配置如下(已满足集成一些常用[ umi 插件] ( https://github.com/umijs/plugins ) 的需要):
174
154
175
155
- [x] [ alias] ( https://umijs.org/config#alias )
176
- - [x] [ chainWebpack] ( https://umijs.org/config#chainwebpack ) :其中` createCSSRule ` 不生效,不支持添加 webpack 插件,使用` lodash.defaultsDeep(userConfig, haulWebapckConfig) ` 合并,这里注入的用户配置优先级高于[ haul] ( https://github.com/callstack/haul ) 配置
177
- - [x] [ dynamicImport] ( https://umijs.org/config#dynamicimport )
178
156
- [x] [ extraBabelPlugins] ( https://umijs.org/config#extrababelplugins )
179
157
- [x] [ extraBabelPresets] ( https://umijs.org/config#extrababelpresets )
180
158
- [x] [ history] ( https://umijs.org/config#history ) :只能使用:` { type: 'memory' } `
@@ -189,59 +167,32 @@ _与 DOM 无关的[umi](https://umijs.org/)插件都是可以使用的,或者
189
167
190
168
_ 上文未列出的[ umi 配置] ( https://umijs.org/config ) 对 ** umi-preset-react-native** 不生效。_
191
169
192
- [ haul ] ( https://github.com/callstack/haul ) 使用的 devServer 是 [ hapi ] ( https://hapi.dev/ ) ,目前还不支持扩展额外的 hapi 插件(中间件),暂时无法支持 [ mock ] ( https://umijs.org/config#mock ) 和 [ proxy ] ( https://umijs.org/config#proxy ) 功能。
170
+ ** 注意 ** :
193
171
194
- ### umi-preset-react-native 扩展配置
172
+ 使用 ** umi-preset-react-native** 会在 RN 工程根目录下生成以下临时文件:
195
173
196
- ``` javascript
197
- // .umirc.js
198
- export default {
199
- reactNative: {
200
- appKey: require (' ./app.json' ).name ,
201
- version: require (' react-native/package.json' ).version ,
202
- },
203
- haul: {
204
- bundles: {
205
- index: {
206
- entry: ' ./umi.ts' ,
207
- },
208
- },
209
- },
210
- };
211
- ```
174
+ - index.js
175
+ - babel.config.js
176
+ - metro.config.js
212
177
213
- - ` reactNative ` :选填,默认值:上面代码示例中的值;
214
- - ` haul ` :选填,默认值:上面代码示例中的值,即[ Project Configuration] ( https://github.com/callstack/haul/blob/master/docs/Configuration.md#project-configuration-reference ) 。
178
+ ` react-native init ` 得到的这 3 个原文件将会被覆盖。
215
179
216
- ## 使用
180
+ 额外添加 Babel 配置只能在 ` umirc.js ` 中使用 [ extraBabelPlugins ] ( https://umijs.org/config#extrababelplugins ) 和 [ extraBabelPresets ] ( https://umijs.org/config#extrababelpresets ) 配置项。
217
181
218
- ### 开发
182
+ 额外添加 [ Metro 配置 ] ( https://facebook.github.io/metro/docs/configuration ) 需要使用环境变量: [ UMI_ENV ] ( https://umijs.org/docs/env-variables#umi_env ) 指定要加载的配置文件: ` metro.${UMI_ENV}.config.js ` 。
219
183
220
- 修改 ` package.json ` 文件,使用 ` umi ` 取代 ` react-native ` :
184
+ 比如,执行 ` UMI_ENV=dev umi watch ` 时,会加载 ` metro.dev.config.js ` 文件中的配置,使用 [ mergeConfig ] ( https://facebook.github.io/metro/docs/configuration#merging-configurations ) 同 ` metro.config.js ` 中的配置进行合并。
221
185
222
- ``` diff
223
- {
224
- "scripts": {
225
- "android": "react-native run-android",
226
- "ios": "react-native run-ios",
227
- - "start": "react-native start",
228
- + "start": "umi dev-rn",
229
- },
230
- }
231
- ```
186
+ ## 使用
232
187
233
- 启动 dev web server:
188
+ ### 开发
189
+
190
+ 先执行 umi watch 监听源码文件变动,重新生成临时代码:
234
191
235
192
``` npm
236
- yarn start
193
+ yarn watch
237
194
```
238
195
239
- 执行上面命令后,会看到:
240
-
241
- ![ ] ( https://cdn.xuyuanxiang.me/start_snapshot_332028d2.png )
242
-
243
- _ 需要原生 Android、iOS 应用启动后,请求 bundle URL 时,进度条才会更新。_
244
-
245
196
接下来,另启一个终端,编译并启动 Android 应用:
246
197
247
198
``` npm
@@ -256,36 +207,13 @@ yarn ios
256
207
257
208
### 打包
258
209
259
- 构建离线包(offline bundle):
260
-
261
- ``` shell
262
- umi build-rn --platform < ios| android> [--bundle-output relative/to/output/outputPath/js.bundle] [--assets-dest relative/to/outputPath/assets]
263
- ```
210
+ 先使用 umi 生成临时代码:
264
211
265
- _ ` relative/to/output/outputPath ` : 表示相对于[ outputPath] ( https://umijs.org/config#outputpath ) 的路径。_
266
-
267
- package.json:
268
-
269
- ``` diff
270
- {
271
- "scripts": {
272
- "android": "react-native run-android",
273
- "ios": "react-native run-ios",
274
- "start": "umi dev-rn",
275
- + "build:ios": "umi build-rn --platform ios",
276
- + "build:android": "umi build-rn --platform android"
277
- },
278
- }
212
+ ``` npm
213
+ umi g tmp
279
214
```
280
215
281
- - 执行` yarn build:ios ` :
282
- 1 . 构建生成` main.jsbundle ` 文件到` dist/ ` 目录;
283
- 2 . 拷贝静态资源到` dist/assets/ ` 目录。
284
- - 执行` yarn build:android ` :
285
- 1 . 构建生成` index.android.bundle ` 文件到` dist/ ` 目录;
286
- 2 . 拷贝静态资源到` dist/assets/ ` 目录。
287
-
288
- _ ` dist ` 是[ outputPath] ( https://umijs.org/config#outputpath ) 配置项的缺省(默认)值,可在` .umirc.js ` 中配置其他目录。_
216
+ 再使用[ react-native bundle] ( https://github.com/react-native-community/cli/blob/master/docs/commands.md#bundle ) 构建离线包(offline bundle)。
289
217
290
218
## 路由
291
219
@@ -371,61 +299,6 @@ export default Layout;
371
299
372
300
了解详情,请移步至:<a href =" https://github.com/xuyuanxiang/umi-react-native/tree/master/packages/umi-preset-react-navigation#readme " target =" _blank " >umi-preset-react-navigation</a >。
373
301
374
- ## 深入
375
-
376
- ### 切分多 bundle
377
-
378
- > TODO: 这一部分还是理论阶段,有待实践。(先画个饼)
379
-
380
- 参考[ react-native-community/react-native-multibundle] ( https://github.com/react-native-community/react-native-multibundle ) 。
381
-
382
- 使用 haul 切分多 bundle:
383
-
384
- ``` javascript
385
- // .umirc.js
386
- export default {
387
- haul: {
388
- templates: {
389
- filename: {
390
- ios: ' [bundleName].ios.bundle' ,
391
- },
392
- },
393
- features: {
394
- multiBundle: 2 ,
395
- },
396
- bundles: {
397
- index: {
398
- entry: [' ./umi.ts' , ' react' , ' react-native' ],
399
- dll: true ,
400
- type: ' indexed-ram-bundle' ,
401
- },
402
- host: {
403
- entry: ' @/app.js' ,
404
- dependsOn: [' index' ],
405
- app: true ,
406
- },
407
- login: {
408
- entry: ' @/pages/login.js' ,
409
- type: ' indexed-ram-bundle' ,
410
- dependsOn: [' index' ],
411
- app: true ,
412
- },
413
- home: {
414
- entry: ' @/pages/home.js' ,
415
- type: ' indexed-ram-bundle' ,
416
- dependsOn: [' index' ],
417
- app: true ,
418
- },
419
- },
420
- },
421
- };
422
- ```
423
-
424
- ** 注意** :
425
-
426
- - ** 不要** 使用 haul 提供的工具:` makeConfig ` 和` withPolyfills ` ;
427
- - ** 要** 保证主 bundle 中必须包含:` ./umi.ts ` 。
428
-
429
302
## FAQ
430
303
431
304
### hmrClient.send is not a function
@@ -444,10 +317,6 @@ _在 RN 工程`node_modules`目录中找到`metro`并查看版本:_
444
317
cat ./node_modules/metro/package.json | grep version
445
318
```
446
319
447
- ### Live Reloading, Fast Refresh, Hot Replacement... 无法使用
448
-
449
- [ haul] ( https://github.com/callstack/haul ) 不支持:[ haul#issue-682] ( https://github.com/callstack/haul/issues/682 ) 。
450
-
451
320
### 使用 @ant-design/react-native 组件时,报错:Unrecognized font family 'antoutline'
452
321
453
322
[ ant-design/ant-design-mobile-rn#issue-194] ( https://github.com/ant-design/ant-design-mobile-rn/issues/194 ) 中有解决方案。
0 commit comments