-
Notifications
You must be signed in to change notification settings - Fork 13
/
babel.config.js
45 lines (41 loc) · 1.1 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
let fs = require('fs');
module.exports = api => {
api.cache(true);
let modules = JSON.parse(fs.readFileSync('./modules.json', 'utf8')).modules;
const getDeeper = fPath => {
const path = fPath.split('/');
return { parent: path[0], target: path[1] };
};
const checkDeep = fPath => {
if (fPath.indexOf('/') !== -1) {
let { parent, target } = getDeeper(fPath);
let path = `${parent}/${target}`;
return { path, target };
}
return { path: fPath, target: fPath };
};
const alias = modules.reduce(
(aliasAcc, moduleName) => {
const { path, target } = checkDeep(moduleName);
aliasAcc[`@${target}`] = `./App/${path}`;
return aliasAcc;
},
{
// explicitly add redux to avoid conflict with local redux folder's package.json
redux: './node_modules/redux',
},
);
return {
presets: ['module:@react-native/babel-preset'],
plugins: [
[
'module-resolver',
{
root: ['.'],
extensions: ['.ios.js', '.android.js', '.js', '.ts', '.tsx', '.json'],
alias,
},
],
],
};
};