generated from toastyboost/rollup-starter
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbabel.config.js
70 lines (60 loc) · 1.64 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
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 = {};
const babelConfig = {
plugins(meta) {
const alias = parseAliases(meta, aliases);
const result = [
['effector/babel-plugin', { addLoc: true }],
[
'babel-plugin-module-resolver',
{
alias,
loglevel: 'silent',
},
],
];
return result;
},
};
function parseAliases(meta, obj) {
const result = {};
for (const key in obj) {
const value = obj[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);