-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetro.config.js
53 lines (45 loc) · 2.19 KB
/
metro.config.js
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
const { createMetroConfiguration } = require('expo-yarn-workspaces');
const path = require('path');
const baseConfig = createMetroConfiguration(__dirname);
// To test home from Expo Go, the react-native js source is from our fork.
const reactNativeRoot = path.join(__dirname, '..', 'react-native-lab', 'react-native');
module.exports = {
...baseConfig,
// NOTE(brentvatne): This can be removed when
// https://github.com/facebook/metro/issues/290 is fixed.
server: {
enhanceMiddleware: (middleware) => {
return (req, res, next) => {
// When an asset is imported outside the project root, it has wrong path on Android
// This happens for the back button in stack, so we fix the path to correct one
const assets = '/node_modules/@react-navigation/elements/src/assets';
if (req.url.startsWith(assets)) {
req.url = req.url.replace(assets, `/assets/..${assets}`);
}
return middleware(req, res, next);
};
},
},
resolver: {
...baseConfig.resolver,
blockList: [
...baseConfig.resolver.blockList,
// Because react-native versions may be different between node_modules/react-native and react-native-lab,
// metro and react-native cannot serve duplicated files from different paths.
// Assuming home only serves for Expo Go,
// the strategy here is to serve react-native imports from `react-native-lab/react-native` but not its transitive dependencies.
// That is not ideal but should work for most cases if the two react-native versions do not have too much difference.
// For example, `react-native-lab/react-native/node_modules/@react-native/polyfills` and `node_modules/@react-native/polyfills` may be different,
// the metro config will use the transitive dependency from `node_modules/@react-native/polyfills`.
/\bnode_modules\/react-native\//,
/\breact-native-lab\/react-native\/node_modules\b/,
],
},
serializer: {
...baseConfig.serializer,
getModulesRunBeforeMainModule: () => [
require.resolve(path.join(reactNativeRoot, 'Libraries/Core/InitializeCore')),
],
getPolyfills: () => require(path.join(reactNativeRoot, 'rn-get-polyfills'))(),
},
};