-
Notifications
You must be signed in to change notification settings - Fork 0
/
babel.config.js
32 lines (27 loc) · 998 Bytes
/
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
import packageConfig from './package.json';
/**
* Converts the "imports" entry of the root-level ./package.json to aliases
* for use in the `babel-plugin-module-resolver` babel plugin
*/
const fetchPackageImportsAsAliasMap = () => {
const imports = packageConfig.imports;
const importEntries = Object.entries(imports);
const removeTrailingExpansion = (item) => item.replace(/\/\*$/, '');
const moduleToCommonjsDir = (item) => item.replace(/^\.\/src/, './lib');
const importAliasTransformer = ([key, val]) => [
removeTrailingExpansion(moduleToCommonjsDir(key)),
removeTrailingExpansion(val),
];
const aliasImportEntries = importEntries.map(importAliasTransformer);
return Object.fromEntries(aliasImportEntries);
};
const aliasImports = fetchPackageImportsAsAliasMap();
export default {
'presets': [
['@babel/preset-env'],
],
'plugins': [
['@babel/plugin-transform-runtime', {'regenerator': true}],
['module-resolver', {'alias': aliasImports}],
],
};