metro.config.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
  2. const path = require('path');
  3. const escape = require('escape-string-regexp');
  4. const exclusionList = require('metro-config/src/defaults/exclusionList');
  5. const pak = require('../package.json');
  6. const root = path.resolve(__dirname, '..');
  7. const modules = Object.keys({ ...pak.peerDependencies });
  8. /**
  9. * Metro configuration
  10. * https://facebook.github.io/metro/docs/configuration
  11. *
  12. * @type {import('metro-config').MetroConfig}
  13. */
  14. const config = {
  15. watchFolders: [root],
  16. // We need to make sure that only one version is loaded for peerDependencies
  17. // So we block them at the root, and alias them to the versions in example's node_modules
  18. resolver: {
  19. blacklistRE: exclusionList(
  20. modules.map(
  21. (m) =>
  22. new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
  23. )
  24. ),
  25. extraNodeModules: modules.reduce((acc, name) => {
  26. acc[name] = path.join(__dirname, 'node_modules', name);
  27. return acc;
  28. }, {}),
  29. },
  30. transformer: {
  31. getTransformOptions: async () => ({
  32. transform: {
  33. experimentalImportSupport: false,
  34. inlineRequires: true,
  35. },
  36. }),
  37. },
  38. };
  39. module.exports = mergeConfig(getDefaultConfig(__dirname), config);