-
-
Notifications
You must be signed in to change notification settings - Fork 853
/
metro.config.js
101 lines (84 loc) · 2.69 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// https://github.com/callstack/react-native-builder-bob/blob/main/packages/create-react-native-library/templates/expo-library/example/metro.config.js
const path = require('path');
const { getDefaultConfig } = require('expo/metro-config');
const exclusionList = require('metro-config/src/defaults/exclusionList');
const escape = require('escape-string-regexp');
const root = path.resolve(__dirname, '..');
const libPackageJson = require('../package.json');
const libPeerDependencies = Object.keys(libPackageJson.peerDependencies)
.concat([
'@babel/runtime',
'react-native-web',
'@react-native/assets-registry',
])
.concat(Object.keys(libPackageJson.dependencies));
const modules = libPeerDependencies;
/** @type {import('expo/metro-config').MetroConfig} */
const defaultConfig = getDefaultConfig(__dirname);
/**
* Metro configuration
* https://reactnative.dev/docs/metro
*
* @type {import('metro-config').MetroConfig}
*/
const config = {
...defaultConfig,
projectRoot: __dirname,
watchFolders: [root],
resolver: {
...defaultConfig.resolver,
blacklistRE: exclusionList(
modules.map(
(m) =>
new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`),
),
),
extraNodeModules: modules.reduce((acc, name) => {
acc[name] = path.join(__dirname, 'node_modules', name);
return acc;
}, {}),
assetExts: [...defaultConfig.resolver.assetExts, 'gltf', 'glb'],
},
transformer: {
...defaultConfig.transformer,
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
};
const fixWebExportToUseWebSuffixForRNMBX = true;
if (fixWebExportToUseWebSuffixForRNMBX) {
config.resolver.resolveRequest = (context, moduleName, platform) => {
let result = null;
if (platform === 'web' && moduleName === path.join(root, 'src', 'index')) {
result = context.resolveRequest(context, moduleName + '.web', platform);
} else {
result = context.resolveRequest(context, moduleName, platform);
}
return result;
};
}
const debugModuleResolution = false;
if (debugModuleResolution) {
config.maxWorkers = 1;
config.resolver.resolveRequest = (context, moduleName, platform) => {
let result = null;
if (platform === 'web' && moduleName === path.join(root, 'src', 'index')) {
result = context.resolveRequest(context, moduleName + '.web', platform);
} else {
result = context.resolveRequest(context, moduleName, platform);
}
console.log(
' => resolveRequest',
context.originModulePath,
moduleName,
platform,
result,
);
return result;
};
}
module.exports = config;