File tree 5 files changed +34
-11
lines changed
packages/preset/src/plugins/generateFiles
5 files changed +34
-11
lines changed Original file line number Diff line number Diff line change 23
23
24
24
RN 示例工程:[ UMIRNExample] ( https://github.com/xuyuanxiang/UMIRNExample )
25
25
26
- - [ compare/0.0.1...0.1.0] ( https://github.com/xuyuanxiang/UMIRNExample/compare/0.0.1...0.1.0 ) :使用` react-native init ` 初始化工程 到 集成 ` umi-preset-react-native ` 后的改动内容。
26
+ - [ 0.0.1] ( https://github.com/xuyuanxiang/UMIRNExample/tree/0.0.1 ) : 使用` react-native init ` 得到的初始工程
27
+ - [ 0.1.0] ( https://github.com/xuyuanxiang/UMIRNExample/tree/0.1.0 ) :添加` umi ` 依赖并集成` umi-preset-react-native `
28
+ - [ compare/0.0.1...0.1.0] ( https://github.com/xuyuanxiang/UMIRNExample/compare/0.0.1...0.1.0 )
29
+ - [ 1.0.0] ( https://github.com/xuyuanxiang/UMIRNExample/tree/1.0.0 ) :集成` @umijs/plugin-dva `
30
+ - [ compare/0.0.1...1.0.0] ( https://github.com/xuyuanxiang/UMIRNExample/compare/0.0.1...1.0.0 )
31
+ - [ compare/0.1.0...1.0.0] ( https://github.com/xuyuanxiang/UMIRNExample/compare/0.1.0...1.0.0 )
27
32
28
33
## 安装
29
34
@@ -66,7 +71,7 @@ export default {
66
71
67
72
- ` history ` :在 RN 中只能使用:` 'memory' ` 类型,[ umi] ( https://umijs.org/ ) 默认值是:` 'browser' ` 。` 'browser' ` 和` 'hash' ` 类型都需要 DOM,在 RN 中会报错;
68
73
69
- _ umi 3.x 后会自动探测宿主工程` devDependencies ` 和` dependencies ` 中所有含 ` umi-preset- ` 和 ` umi-plugin- ` 前缀的 npm 包,自动装配。所以不再需要在 ` .umirc.js ` 中配置` plugins ` 和` presets ` _
74
+ _ umi 3.x 后会自动探测宿主工程` devDependencies ` 和` dependencies ` 并自动装配插件。所以不需要在 ` .umirc.js ` 中配置` plugins ` 和` presets ` 选项。 _
70
75
71
76
** 在 RN 中集成其他[ umi] ( https://umijs.org/ ) 插件需要开发者自行斟酌。**
72
77
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ const transform = ({ config }) => {
13
13
export default makeConfig({
14
14
bundles: {
15
15
index: {
16
- entry: withPolyfills('./index.js '),
16
+ entry: withPolyfills('./index.ts '),
17
17
transform,
18
18
},
19
19
},
@@ -49,7 +49,7 @@ export default (api: IApi) => {
49
49
return bundleConfig . entry ?. umi ;
50
50
} ) [ 0 ] ;
51
51
52
- const alias = lodash . omit ( config . resolve ?. alias , [ 'react-dom' ] ) ;
52
+ const alias = lodash . cloneDeep ( config . resolve ?. alias ) ;
53
53
Object . assign ( alias , {
54
54
// 防止加载umi Common JS格式的代码
55
55
umi : winPath ( join ( absTmpPath || '' , 'rn' , 'umi' ) ) ,
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ export default (api: IApi) => {
19
19
20
20
api . onGenerateFiles ( async ( ) => {
21
21
api . writeTmpFile ( {
22
- path : 'index.js ' ,
22
+ path : 'index.ts ' ,
23
23
content : Mustache . render ( indexTpl , {
24
24
appKey : api . config ?. reactNative ?. appKey ,
25
25
entryCode : (
@@ -36,6 +36,13 @@ export default (api: IApi) => {
36
36
initialValue : [ ] ,
37
37
} )
38
38
) . join ( '\r\n' ) ,
39
+ polyfillImports : importsToStr (
40
+ await api . applyPlugins ( {
41
+ key : 'addPolyfillImports' ,
42
+ type : api . ApplyPluginsType . add ,
43
+ initialValue : [ ] ,
44
+ } ) ,
45
+ ) . join ( '\r\n' ) ,
39
46
importsAhead : importsToStr (
40
47
await api . applyPlugins ( {
41
48
key : 'addEntryImportsAhead' ,
Original file line number Diff line number Diff line change 1
- export default `
1
+ export default `// @ts-ignore
2
2
if (global.window === undefined) {
3
+ // @ts-ignore
3
4
global.window = global;
4
5
}
5
-
6
+ {{{ polyfillImports }}}
6
7
{{{ importsAhead }}}
7
8
import {ApplyPluginsType} from 'umi-react-native-runtime';
8
9
import {renderClient} from 'umi-react-native-renderer';
9
- import {plugin, history} from './core/umiExports';
10
+ import {plugin} from './core/umiExports';
11
+ import {createHistory} from './core/history';
10
12
import {routes} from './core/routes';
11
13
{{{ imports }}}
12
14
13
15
{{{ entryCodeAhead }}}
14
16
15
- const getClientRender = (args = {}) => plugin.applyPlugins({
17
+ const getClientRender = (args: { hot?: boolean } = {}) => plugin.applyPlugins({
16
18
key: 'render',
17
19
type: ApplyPluginsType.compose,
18
20
initialValue: () => {
19
21
return renderClient({
20
22
routes,
21
23
plugin,
22
- history,
24
+ history: createHistory(args.hot) ,
23
25
appKey: '{{{ appKey }}}',
24
26
});
25
27
},
@@ -32,4 +34,13 @@ export default clientRender();
32
34
33
35
{{{ entryCode }}}
34
36
37
+ // hot module replacement
38
+ // @ts-ignore
39
+ if (module.hot) {
40
+ // @ts-ignore
41
+ module.hot.accept(() => {
42
+ getClientRender({ hot: true })();
43
+ });
44
+ }
45
+
35
46
` ;
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export * from '../core/umiExports';
14
14
export default ( api : IApi ) => {
15
15
api . onGenerateFiles ( async ( ) => {
16
16
api . writeTmpFile ( {
17
- path : 'rn/umi.js ' ,
17
+ path : 'rn/umi.ts ' ,
18
18
content : CONTENT ,
19
19
} ) ;
20
20
} ) ;
You can’t perform that action at this time.
0 commit comments