-
Notifications
You must be signed in to change notification settings - Fork 55
/
metro.config.js
86 lines (77 loc) · 2.53 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
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
const { getDefaultConfig } = require('metro-config')
const nodeLibs = require('node-libs-react-native')
/**
*
* packages that use new package.json export.
* solving issues with latest ceramic
*/
const packageExports = {
"varintes": "",
"multihashes-sync": "",
"cartonne": "",
"codeco": "",
"multiformats": "./node_modules/multiformats/cjs/src/",
}
module.exports = (async () => {
const {
resolver: { sourceExts, assetExts },
} = await getDefaultConfig()
const defaultSourceExts = [...sourceExts, 'svg', 'mjs', 'cjs', 'jsx']
return {
resolver: {
resolveRequest: (context, moduleName, platform) => {
const [packageName, ...packagePath] = moduleName.split("/")
const packageExport = packageExports[packageName]
const packagePathJoined = packagePath.join("/")
let filePath
if (packageExport !== undefined) {
try {
console.log("resolving", {moduleName, packageExport, packagePath})
// indexeddbshim case
if (packageExport.length > 0 && packagePathJoined.length === 0) {
filePath = require.resolve(packageExport);
}
if (packageExport.length > 0) {
filePath = require.resolve(packageExport + packagePathJoined)
}
else {
filePath = require.resolve(`./node_modules/${packageName}/dist/${packagePathJoined || 'index.js'}`)
}
return {
filePath,
type: 'sourceFile',
}
}
catch (e) {
console.log("failed resolving", {moduleName, packageExport, packagePath, filePath, }, e.message)
}
}
// Optionally, chain to the standard Metro resolver.
return context.resolveRequest(context, moduleName, platform);
},
extraNodeModules: {
...nodeLibs,
vm: require.resolve('vm-browserify'),
"node:crypto": nodeLibs.crypto,
fs: require.resolve('react-native-fs'),
},
assetExts: assetExts.filter(ext => ext !== 'svg'),
sourceExts: process.env.TEST_REACT_NATIVE ? ['e2e.js'].concat(defaultSourceExts) : defaultSourceExts,
},
transformer: {
babelTransformerPath: require.resolve('react-native-svg-transformer'),
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
}
})()