-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmetro.config.js
More file actions
72 lines (59 loc) · 2.34 KB
/
Copy pathmetro.config.js
File metadata and controls
72 lines (59 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Learn more: https://docs.expo.dev/guides/monorepos/
const { getDefaultConfig } = require('expo/metro-config')
const { resolve: resolveRequest } = require('metro-resolver')
const path = require('path')
const expoPackageRoot = path.dirname(require.resolve('expo/package.json'))
const exclusionList = require(
require.resolve('@expo/metro/metro-config/defaults/exclusionList', {
paths: [expoPackageRoot],
})
).default
const PACKAGE_NAME = 'react-native-better-clustering'
const projectRoot = __dirname
const monorepoRoot = path.resolve(projectRoot, '..')
const libraryRoot = path.resolve(monorepoRoot, 'package')
const config = getDefaultConfig(projectRoot)
// Watch the whole monorepo so changes to the local library source are picked up.
config.watchFolders = [monorepoRoot]
const exampleNodeModules = path.resolve(projectRoot, 'node_modules')
// Resolve modules from the example first, then the hoisted monorepo root.
config.resolver.nodeModulesPaths = [
exampleNodeModules,
path.resolve(monorepoRoot, 'node_modules'),
]
// Single canonical entry for the local package (avoids symlink + watchFolder duplicates).
config.resolver.extraNodeModules = {
[PACKAGE_NAME]: libraryRoot,
}
// Never bundle compiled `lib/` output while developing against `src/`.
config.resolver.blockList = exclusionList([
new RegExp(
`${path.resolve(libraryRoot, 'lib').replace(/[/\\]/g, '[/\\\\]')}[/\\\\].*`
),
])
// The library has its own `react` and `react-native-maps` (devDependencies).
// When Metro bundles the library `src`, hierarchical lookup can pick those
// copies instead of the example app's singletons — force shared packages to
// the example.
function resolveFromExample(moduleName) {
return {
type: 'sourceFile',
filePath: require.resolve(moduleName, { paths: [exampleNodeModules] }),
}
}
config.resolver.resolveRequest = (context, moduleName, platform) => {
if (
moduleName === 'react' ||
moduleName.startsWith('react/') ||
moduleName === 'react-native' ||
moduleName.startsWith('react-native/') ||
moduleName === 'react-native-nitro-modules' ||
moduleName.startsWith('react-native-nitro-modules/') ||
moduleName === 'react-native-maps' ||
moduleName.startsWith('react-native-maps/')
) {
return resolveFromExample(moduleName)
}
return resolveRequest(context, moduleName, platform)
}
module.exports = config