-
Notifications
You must be signed in to change notification settings - Fork 625
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default to lazy requires for all public RN exports (#362)
Summary: **Summary** This commit changes `metro-react-native-babel-preset` to emit lazy `require` calls for all of RN's public exports. This is so that we can move RN to use ES import/export, which syntactically have no lazy version, while preserving the lazy behavior we have today by default. If the developer specifies `lazyImportExportTransform: true`, all imports/exports will be lazy including RN's public exports, so they will remain lazy. (Also, this PR allows developers to specify non-boolean values for `lazyImportExportTransform` e.g. an array of whitelisted paths.) Note: this commit must land and be published before RN can use ESM since the iOS E2E tests depend on the current lazy `require` calls. See the draft PR for RN here: facebook/react-native#23591 **Test plan** Used this module inside of the RN E2E iOS tests and loaded the bundle successfully. Also used it in RNTester. Pull Request resolved: #362 Differential Revision: D14434999 Pulled By: cpojer fbshipit-source-id: d280a8216c6e1c6604e8fea508f5a48f4c1c071b
- Loading branch information
1 parent
123bdf7
commit 23e3503
Showing
2 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
packages/metro-react-native-babel-preset/src/configs/lazy-imports.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* This is the set of modules that React Native publicly exports and that we | ||
* want to require lazily. Keep this list in sync with | ||
* Libraries/react-native/react-native-implementation.js (though having extra | ||
* entries here is fairly harmless). | ||
* @format | ||
*/ | ||
'use strict'; | ||
|
||
module.exports = new Set([ | ||
'AccessibilityInfo', | ||
'ActivityIndicator', | ||
'ReactNativeART', | ||
'Button', | ||
'CheckBox', | ||
'DatePickerIOS', | ||
'DrawerLayoutAndroid', | ||
'FlatList', | ||
'Image', | ||
'ImageBackground', | ||
'ImageEditor', | ||
'ImageStore', | ||
'InputAccessoryView', | ||
'KeyboardAvoidingView', | ||
'ListView', | ||
'MaskedViewIOS', | ||
'Modal', | ||
'Picker', | ||
'PickerIOS', | ||
'ProgressBarAndroid', | ||
'ProgressViewIOS', | ||
'SafeAreaView', | ||
'ScrollView', | ||
'SectionList', | ||
'SegmentedControlIOS', | ||
'Slider', | ||
'Switch', | ||
'RefreshControl', | ||
'StatusBar', | ||
'SwipeableFlatList', | ||
'SwipeableListView', | ||
'Text', | ||
'TextInput', | ||
'ToolbarAndroid', | ||
'Touchable', | ||
'TouchableHighlight', | ||
'TouchableNativeFeedback', | ||
'TouchableOpacity', | ||
'TouchableWithoutFeedback', | ||
'View', | ||
'ViewPagerAndroid', | ||
'VirtualizedList', | ||
'WebView', | ||
|
||
// APIs | ||
'ActionSheetIOS', | ||
'Alert', | ||
'Animated', | ||
'AppRegistry', | ||
'AppState', | ||
'AsyncStorage', | ||
'BackHandler', | ||
'CameraRoll', | ||
'Clipboard', | ||
'DatePickerAndroid', | ||
'DeviceInfo', | ||
'Dimensions', | ||
'Easing', | ||
'ReactNative', | ||
'I18nManager', | ||
'ImagePickerIOS', | ||
'InteractionManager', | ||
'Keyboard', | ||
'LayoutAnimation', | ||
'Linking', | ||
'NativeEventEmitter', | ||
'NetInfo', | ||
'PanResponder', | ||
'PermissionsAndroid', | ||
'PixelRatio', | ||
'PushNotificationIOS', | ||
'Settings', | ||
'Share', | ||
'StatusBarIOS', | ||
'StyleSheet', | ||
'Systrace', | ||
'TimePickerAndroid', | ||
'ToastAndroid', | ||
'TVEventHandler', | ||
'UIManager', | ||
'ReactNative', | ||
'UTFSequence', | ||
'Vibration', | ||
'YellowBox', | ||
|
||
// Plugins | ||
'RCTDeviceEventEmitter', | ||
'RCTNativeAppEventEmitter', | ||
'NativeModules', | ||
'Platform', | ||
'processColor', | ||
'requireNativeComponent', | ||
|
||
// Prop Types | ||
'DeprecatedColorPropType', | ||
'DeprecatedEdgeInsetsPropType', | ||
'DeprecatedPointPropType', | ||
'DeprecatedViewPropTypes', | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters