File tree 3 files changed +43
-5
lines changed
packages/umi-preset-react-native/src
plugins/generateFiles/react-native
3 files changed +43
-5
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ export default function () {
5
5
require . resolve ( './plugins/features/haul' ) ,
6
6
require . resolve ( './plugins/features/reactNative' ) ,
7
7
require . resolve ( './plugins/generateFiles/react-native/exports' ) ,
8
+ require . resolve ( './plugins/generateFiles/react-native/globals' ) ,
8
9
require . resolve ( './plugins/generateFiles/react-native/loading' ) ,
9
10
require . resolve ( './plugins/generateFiles/react-native/polyfill' ) ,
10
11
require . resolve ( './plugins/generateFiles/react-native/routes' ) ,
Original file line number Diff line number Diff line change
1
+ import { IApi } from 'umi' ;
2
+
3
+ const TPL = `{{{ globals }}}
4
+
5
+ ` ;
6
+
7
+ export default ( api : IApi ) => {
8
+ const {
9
+ utils : { Mustache, lodash } ,
10
+ } = api ;
11
+ api . addPolyfillImports ( ( ) => {
12
+ if ( lodash . isPlainObject ( api . config . define ) && ! lodash . isEmpty ( api . config . define ) ) {
13
+ return [
14
+ {
15
+ source : './react-native/globals' ,
16
+ } ,
17
+ ] ;
18
+ }
19
+ return [ ] ;
20
+ } ) ;
21
+ api . onGenerateFiles ( ( ) => {
22
+ if ( lodash . isPlainObject ( api . config . define ) && ! lodash . isEmpty ( api . config . define ) ) {
23
+ api . writeTmpFile ( {
24
+ path : 'react-native/globals.ts' ,
25
+ content : Mustache . render ( TPL , {
26
+ globals : lodash
27
+ . keysIn ( api . config . define )
28
+ . map (
29
+ ( key ) =>
30
+ `// @ts-ignore\nglobal['${ key } '] = ${ JSON . stringify ( api . config . define && api . config . define [ key ] ) } ;` ,
31
+ )
32
+ . join ( '\n' ) ,
33
+ } ) ,
34
+ } ) ;
35
+ }
36
+ } ) ;
37
+ } ;
Original file line number Diff line number Diff line change @@ -22,11 +22,11 @@ export default (api: IApi) => {
22
22
} ) ;
23
23
24
24
api . addEntryCodeAhead ( ( ) => {
25
- if ( api . config . define && typeof api . config . define === 'object ' ) {
26
- const keys = Object . keys ( api . config . define ) ;
27
- return keys
28
- . map ( ( key ) => `global[' ${ key } '] = ${ JSON . stringify ( api . config . define && api . config . define [ key ] ) } ;` )
29
- . join ( '\n' ) ;
25
+ if ( process . env . NODE_ENV === 'development ' ) {
26
+ return `if (__DEV__) {
27
+ const PropsTypes = require('prop-types');
28
+ require('@umijs/runtime').Link.propTypes.component = PropsTypes.oneOfType([PropsTypes.func, PropsTypes.elementType]);
29
+ }` ;
30
30
}
31
31
return '' ;
32
32
} ) ;
You can’t perform that action at this time.
0 commit comments