Repository navigation
Expand file tree
/
Copy pathmetro.config.js
More file actions
46 lines (37 loc) · 1.45 KB
/
Copy pathmetro.config.js
File metadata and controls
46 lines (37 loc) · 1.45 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
const path = require('path');
const { getDefaultConfig } = require('expo/metro-config');
const pkg = require('../package.json');
const root = path.resolve(__dirname, '..');
// Dedupe the library's peer deps (react, react-native) to the example's copy,
// so Metro never loads a second react-native from the library root's own
// node_modules (the library dev-installs a different RN version).
const peers = Object.keys(pkg.peerDependencies || {});
function escapeRegExp(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
/**
* Standalone Metro config (the example is NOT a yarn workspace). It watches the
* library source at `../src` so edits hot-reload without a `bob build`, while
* resolving react / react-native from the example's own node_modules.
*/
const config = getDefaultConfig(__dirname);
config.watchFolders = [root];
const blockedPeerPaths = peers.map(
(name) =>
new RegExp(`^${escapeRegExp(path.join(root, 'node_modules', name))}\\/.*$`)
);
// Merge with Expo's default blockList rather than replace it.
const existingBlockList = config.resolver.blockList;
config.resolver.blockList = existingBlockList
? [
...(Array.isArray(existingBlockList)
? existingBlockList
: [existingBlockList]),
...blockedPeerPaths,
]
: blockedPeerPaths;
config.resolver.extraNodeModules = peers.reduce((acc, name) => {
acc[name] = path.join(__dirname, 'node_modules', name);
return acc;
}, {});
module.exports = config;