generated from toastyboost/rollup-starter
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbabel.config.js
77 lines (69 loc) · 1.78 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
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',
},
foliage: {
esm: 'foliage/index.mjs',
},
forest: {
esm: 'forest/forest.mjs',
},
};
const babelConfig = {
presets: ['@babel/preset-env', '@babel/preset-typescript', 'solid'],
plugins(meta) {
const alias = parseAliases(meta, aliases);
return [
['effector/babel-plugin', { addLoc: true }],
[
'babel-plugin-module-resolver',
{
alias,
loglevel: 'silent',
},
],
];
},
};
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);