-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabel.config.js
66 lines (59 loc) · 1.34 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
// @flow strict
/*::
type ApiType = {|
+assertVersion: number => void,
+cache: {|
forever: () => void,
|},
+caller: (Caller => boolean) => boolean,
|};
type Caller = {|
+name: string,
|};
type BabelConfig = {|
+presets: $ReadOnlyArray<string | [string, { ... }]>,
+babelrcRoots: $ReadOnlyArray<string>,
|};
*/
function isWebpack(caller) /*: boolean %checks */ {
// https://github.com/babel/babel-loader
return !!(caller && caller.name === 'babel-loader');
}
function getTarget() {
const extensionIndex = process.argv.findIndex((i) => i === '--out-file-extension');
if (extensionIndex >= 0) {
const extension = process.argv[extensionIndex + 1];
switch (extension) {
case '.mjs':
return 'js-esm';
case '.js.flow':
return 'flow';
default:
break;
}
}
return null;
}
module.exports = function (api /*: ApiType */) /*: BabelConfig */ {
api.assertVersion(7);
let target = getTarget();
if (target == null) {
target = api.caller(isWebpack) ? 'js-esm' : 'js';
} else {
api.cache.forever();
}
return {
presets: [
[
'@adeira/babel-preset-adeira',
{
target,
},
],
],
babelrcRoots: [
'.', // keep the root as a root
'./src/*', // also consider all packages and load their .babelrc files.
],
};
};