-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbabel.config.js
103 lines (94 loc) · 2.43 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
const { resolve: resolvePath } = require('path');
module.exports = (api) => {
api && api.cache && api.cache.never && api.cache.never();
// const env = api.cache(() => process.env.NODE_ENV)
return generateConfig(meta, babelConfig);
};
const meta = {
isEsm: true,
};
function generateConfig(meta, config = babelConfig) {
const result = {};
for (const key in config) {
const value = config[key];
result[key] = typeof value === 'function' ? value(meta) : value;
}
return result;
}
module.exports.generateConfig = generateConfig;
const aliases = {
effector: {
esm: 'effector/effector.mjs',
},
forest: {
esm: 'forest/forest.mjs',
},
stylis: {
esm: 'stylis/dist/stylis.mjs',
},
};
const babelConfig = {
presets: [
'@babel/preset-env',
'@babel/preset-typescript',
'@babel/preset-react',
],
plugins: [
// [
// './babel-plugin.js',
// {
// allowedModules: ['foliage', '../../react'],
// },
// ],
],
// plugins(meta) {
// const alias = parseAliases(meta, aliases);
// return [
// // [
// // require.resolve('./babel-plugin.js'),
// // {
// // allowedModules: ['../foliage', 'foliage', '../../react'],
// // debug: false,
// // },
// // ],
// // ['effector/babel-plugin', { addLoc: true }],
// // [
// // 'babel-plugin-module-resolver',
// // {
// // alias: {
// // ...alias,
// // foliage: './react',
// // },
// // loglevel: 'silent',
// // },
// // ],
// ];
// },
};
// eslint-disable-next-line sonarjs/cognitive-complexity
function parseAliases(meta, object) {
const result = {};
for (const key in object) {
const value = object[key];
if (typeof value === 'function') {
const name = value(meta);
if (name === undefined || name === null) continue;
result[key] = name;
} else if (typeof value === 'object' && value !== null) {
const name = applyPaths(value);
if (name === undefined || name === null) continue;
result[key] = name;
} else {
const name = value;
if (name === undefined || name === null) continue;
result[key] = name;
}
}
return result;
function applyPaths(paths) {
if (meta.isEsm) return paths.esm;
return paths.default;
}
}
module.exports.getAliases = (metadata = meta) =>
parseAliases(metadata, aliases);