forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetro.config.js
77 lines (72 loc) · 2.16 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
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
/* eslint-disable */
const {getDefaultConfig} = require('metro-config')
const {resolve} = require('metro-resolver')
const {replacements} = require('./mocks')
let storybook = 'none'
module.exports = (async () => {
const {
resolver: {sourceExts},
} = await getDefaultConfig()
// If we're in storybook mode, apply some mocks. The initial request from the RN app
// tells us whether we are in storybook mode or normal mode.
// The desktop equivalents of these mocks are in `shared/.storybook/webpack.config.js`.
const mockingResolveRequest = (context, moduleName, platform) => {
let newModuleName = moduleName
if (moduleName === './storybook-index') {
if (storybook === 'normal') {
console.log('Switching to storybook mode, please restart metro.')
process.exit(12)
}
storybook = 'storybook'
newModuleName = './index'
} else if (moduleName === './normal-index') {
if (storybook === 'storybook') {
console.log('Switching to normal mode, please restart metro')
process.exit(12)
}
storybook = 'normal'
newModuleName = './index'
}
if (storybook === 'storybook') {
replacements.forEach(rep => {
const [regex, replacement] = rep
if (moduleName.match(regex)) {
newModuleName = `./${replacement}.tsx`
}
})
}
// To prevent the metro resolver from just turning around and calling us
context.resolveRequest = null
return resolve(context, newModuleName, platform)
}
return {
resolver: {
resolveRequest: mockingResolveRequest,
sourceExts: [...sourceExts, 'css'],
},
transformer: {
babelTransformerPath: require.resolve('./rn-transformer.js'),
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
minifierConfig: {
mangle: {
keep_fnames: true,
},
compress: {
keep_fnames: true,
keep_classnames: true,
},
},
},
}
})()