暂无描述

react-native.config.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * This cli config is needed for the coexistance of react-native and other
  3. * out-of-tree implementations such react-native-macos.
  4. * The following issue is tracked by
  5. * https://github.com/react-native-community/discussions-and-proposals/issues/182
  6. *
  7. * The work-around involves having a metro.config.js for each out-of-tree
  8. * platform, i.e. metro.config.js for react-native and
  9. * metro.config.macos.js for react-native-macos.
  10. * This react-native.config.js looks for a --use-react-native-macos
  11. * switch and when present pushes --config=metro.config.macos.js
  12. * and specifies reactNativePath: 'node_modules/react-native-macos'.
  13. * The metro.config.js has to blacklist 'node_modules/react-native-macos',
  14. * and conversely metro.config.macos.js has to blacklist 'node_modules/react-native'.
  15. */
  16. 'use strict';
  17. const path = require('path');
  18. const macSwitch = '--use-react-native-macos';
  19. const windowsSwitch = '--use-react-native-windows';
  20. if (process.argv.includes(macSwitch)) {
  21. process.argv = process.argv.filter(arg => arg !== macSwitch);
  22. process.argv.push('--config=metro.config.macos.js');
  23. module.exports = {
  24. reactNativePath: 'node_modules/react-native-macos',
  25. };
  26. }
  27. else if (process.argv.includes(windowsSwitch)) {
  28. process.argv = process.argv.filter(arg => arg !== windowsSwitch);
  29. process.argv.push('--config=metro.config.windows.js');
  30. module.exports = {
  31. reactNativePath: 'node_modules/react-native-windows',
  32. };
  33. }
  34. else {
  35. module.exports = {
  36. project: {
  37. ios: {
  38. project: 'example/ios/',
  39. },
  40. android: {
  41. sourceDir: 'example/android',
  42. },
  43. },
  44. };
  45. }