diff --git a/packages/metro-react-native-babel-preset/src/configs/lazy-imports.js b/packages/metro-react-native-babel-preset/src/configs/lazy-imports.js new file mode 100644 index 0000000000..376eff2291 --- /dev/null +++ b/packages/metro-react-native-babel-preset/src/configs/lazy-imports.js @@ -0,0 +1,106 @@ +/** + * 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). + */ +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', +]); diff --git a/packages/metro-react-native-babel-preset/src/configs/main.js b/packages/metro-react-native-babel-preset/src/configs/main.js index b1d3beebdf..3a84b2ee79 100644 --- a/packages/metro-react-native-babel-preset/src/configs/main.js +++ b/packages/metro-react-native-babel-preset/src/configs/main.js @@ -9,6 +9,8 @@ 'use strict'; +const lazyImports = require('./lazy-imports'); + function isTypeScriptSource(fileName) { return !!fileName && fileName.endsWith('.ts'); } @@ -93,7 +95,10 @@ const getPreset = (src, options) => { { strict: false, strictMode: false, // prevent "use strict" injections - lazy: !!(options && options.lazyImportExportTransform), + lazy: + options && options.lazyImportExportTransform !== undefined + ? options.lazyImportExportTransform + : importSpecifier => lazyImports.has(importSpecifier), allowTopLevelThis: true, // dont rewrite global `this` -> `undefined` }, ],