-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabel.config.js
109 lines (101 loc) · 2.88 KB
/
babel.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
102
103
104
105
106
107
108
109
module.exports = function (api) {
const isLegends = process.env.WEBPACK_BUILD_OUTPUT_PATH?.includes('legends')
api.cache(true)
const pathAliases = {
'@ambire-common': './src/ambire-common/src',
'@contracts': './src/ambire-common/contracts',
// v1 is legacy and should be removed when v1 imports are replaced with @ambire-common
'@ambire-common-v1': './src/ambire-common/v1',
'@common': './src/common',
'@mobile': './src/mobile',
'@web': './src/web',
'@benzin': './src/benzin',
'@legends': './src/legends'
}
const config = {
presets: ['babel-preset-expo'],
plugins: [
['@babel/plugin-proposal-export-namespace-from'],
['transform-inline-environment-variables'],
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-private-methods', { loose: true }],
[
'module:react-native-dotenv',
{
moduleName: '@env',
path: '.env'
}
],
['react-native-reanimated/plugin']
]
}
const webConfig = {
...config,
plugins: [
...config.plugins,
[
'module-resolver',
{
root: ['./src'],
extensions: [
'.ios.ts',
'.android.ts',
'.ts',
'.ios.tsx',
'.android.tsx',
'.tsx',
'.jsx',
'.js',
'.json'
],
alias: pathAliases
}
]
]
}
if (isLegends) {
webConfig.presets = [...webConfig.presets, '@babel/preset-react', '@babel/preset-typescript']
}
const mobileConfig = {
...config,
plugins: [
...config.plugins,
[
'module-resolver',
{
root: ['./src'],
extensions: [
'.ios.ts',
'.android.ts',
'.ts',
'.ios.tsx',
'.android.tsx',
'.tsx',
'.jsx',
'.js',
'.json'
],
alias: {
// alias for better crypto performance on mobile
'scrypt-js': './src/common/config/alias/scrypt.js',
// alias for better crypto performance on mobile
'@ethersproject/pbkdf2': './src/common/config/alias/pbkdf2.js',
// node's crypto polyfill for React Native
crypto: 'react-native-quick-crypto',
// stream-browserify: used by react-native-quick-crypto
stream: 'stream-browserify',
// @craftzdog/react-native-buffer: used by react-native-quick-crypto
buffer: '@craftzdog/react-native-buffer',
// absolute imports
...pathAliases
}
}
]
]
}
const isMobile =
!process.env.WEB_ENGINE &&
!process.env.WEBPACK_BUILD_OUTPUT_PATH?.includes('benzin') &&
!process.env.WEBPACK_BUILD_OUTPUT_PATH?.includes('legends')
return isMobile ? mobileConfig : webConfig
}