|
| 1 | +const { getDefaultConfig } = require('expo/metro-config'); |
| 2 | +const { getConfig } = require('react-native-builder-bob/metro-config'); |
| 3 | +const path = require('path'); |
| 4 | + |
| 5 | +const workspaceRoot = path.resolve(__dirname, '..', '..'); |
| 6 | +const workspacePath = (name) => path.resolve(workspaceRoot, name); |
| 7 | + |
| 8 | +const workspacePackages = [ |
| 9 | + { |
| 10 | + name: '@contentpass/react-native-contentpass', |
| 11 | + root: workspacePath('packages/react-native-contentpass'), |
| 12 | + }, |
| 13 | + { |
| 14 | + name: '@contentpass/react-native-contentpass-ui', |
| 15 | + root: workspacePath('packages/react-native-contentpass-ui'), |
| 16 | + }, |
| 17 | + { |
| 18 | + name: '@contentpass/react-native-contentpass-cmp-consentmanager', |
| 19 | + root: workspacePath('packages/react-native-contentpass-cmp-consentmanager'), |
| 20 | + }, |
| 21 | +]; |
| 22 | + |
| 23 | +const pkg = require('../../packages/react-native-contentpass/package.json'); |
| 24 | +const root = path.resolve(__dirname, '..', '..'); |
| 25 | + |
| 26 | +/** @type {import('expo/metro-config').MetroConfig} */ |
| 27 | +const config = getConfig(getDefaultConfig(__dirname), { |
| 28 | + root, |
| 29 | + pkg, |
| 30 | + project: __dirname, |
| 31 | +}); |
| 32 | + |
| 33 | +config.watchFolders = [ |
| 34 | + ...(config.watchFolders || []), |
| 35 | + ...workspacePackages.flatMap(({ root }) => [path.join(root, 'src'), root]), |
| 36 | +]; |
| 37 | + |
| 38 | +const exampleNodeModules = path.resolve(__dirname, 'node_modules'); |
| 39 | +const rootNodeModules = path.resolve(__dirname, '..', '..', 'node_modules'); |
| 40 | +const libraryNodeModules = path.join( |
| 41 | + workspacePath('packages/react-native-contentpass'), |
| 42 | + 'node_modules' |
| 43 | +); |
| 44 | +const workspaceExtraNodeModules = Object.fromEntries( |
| 45 | + workspacePackages.map(({ name, root }) => [name, path.join(root, 'src')]) |
| 46 | +); |
| 47 | + |
| 48 | +config.resolver = { |
| 49 | + ...config.resolver, |
| 50 | + disableHierarchicalLookup: true, |
| 51 | + extraNodeModules: { |
| 52 | + ...config.resolver?.extraNodeModules, |
| 53 | + 'react': path.join(exampleNodeModules, 'react'), |
| 54 | + 'react-native': path.join(exampleNodeModules, 'react-native'), |
| 55 | + ...workspaceExtraNodeModules, |
| 56 | + }, |
| 57 | + nodeModulesPaths: [ |
| 58 | + exampleNodeModules, |
| 59 | + rootNodeModules, |
| 60 | + libraryNodeModules, |
| 61 | + ...(config.resolver?.nodeModulesPaths || []), |
| 62 | + ], |
| 63 | + unstable_enablePackageExports: false, |
| 64 | +}; |
| 65 | + |
| 66 | +module.exports = config; |
0 commit comments