-
Notifications
You must be signed in to change notification settings - Fork 493
/
babel.config.js
95 lines (84 loc) · 2.19 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
/*
* dependencies of this config should be specified in `./package.json` relative
* to this config file (which should be in the root of the monorepo);
* yarn-workspace hoisting re: dev/Deps specified in
* `packages/utils/collective/package.json` is not reliable re: dependencies of
* this root-level config being resolvable (with correct versions) from the
* monorepo root
*/
const cloneDeep = require('lodash.clonedeep');
module.exports = (api) => {
const env = api.env();
const base = {
babelrcRoots: [
'.',
'packages/*'
],
plugins: [
'babel-plugin-macros',
[
'@babel/plugin-proposal-decorators', {
legacy: true
}
],
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-syntax-dynamic-import',
[
'@babel/plugin-proposal-class-properties', {
loose: true
}
],
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-proposal-optional-chaining',
[
'@babel/plugin-transform-runtime', {
corejs: 3
}
]
],
presets: [
'@babel/preset-env',
'@babel/preset-typescript'
]
};
if (env === 'base' || env.startsWith('base:')) {
return base;
}
const browser = cloneDeep(base);
browser.plugins[browser.plugins.length - 1][1].useESModules = true;
browser.presets[0] = [
browser.presets[0], {
corejs: 3,
modules: false,
shippedProposals: true,
targets: {browsers: ['last 1 version', 'not dead', '> 0.2%']},
useBuiltIns: 'usage'
}
];
if (env === 'browser' || env.startsWith('browser:')) {
return browser;
}
const node = cloneDeep(base);
node.plugins.splice(
node.plugins.indexOf('@babel/plugin-syntax-dynamic-import') + 1,
0,
'babel-plugin-dynamic-import-node'
);
node.presets[0] = [
node.presets[0], {
corejs: 3,
shippedProposals: true,
targets: {node: '10.17.0'},
useBuiltIns: 'usage'
}
];
if (env === 'node' || env.startsWith('node:')) {
return node;
}
const test = cloneDeep(node);
if (env === 'test') {
return test;
}
return {};
};