forked from bbc/simorgh
-
Notifications
You must be signed in to change notification settings - Fork 3
/
.babelrc.js
77 lines (71 loc) · 1.83 KB
/
.babelrc.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
var plugins = [
'@emotion',
'@babel/plugin-proposal-object-rest-spread', // allows ...spread notation
'@babel/plugin-syntax-dynamic-import', // allows `await import()` syntax
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-transform-runtime',
'@loadable/babel-plugin',
];
// allows dynamic `import()` in Node tests.
if (process.env.NODE_ENV === 'test') {
plugins.push('dynamic-import-node');
plugins.push('@babel/plugin-proposal-throw-expressions'); // allows `throw new Error();`
}
if (process.env.NODE_ENV === 'production') {
plugins.push([
'transform-react-remove-prop-types',
{
mode: 'remove',
removeImport: true,
},
]);
}
const overrides = [
{
test: /.*logger\..*/,
sourceType: 'script',
},
];
module.exports = api => {
const env = api.env();
const useModern = env === 'modern';
const presets = [
[
'@babel/preset-env',
{
targets: {
...(useModern
? {
browsers: ['safari > 9', 'supports es6-module'],
}
: {
browsers: [
'chrome >= 53',
'firefox >= 45.0',
'ie >= 11',
'edge >= 37',
'safari >= 9',
'opera >= 40',
'op_mini >= 18',
'Android >= 7',
'and_chr >= 53',
'and_ff >= 49',
'ios_saf >= 10',
],
}),
node: 'current',
},
// analyses code & polyfills only the features that are used, only for the targeted browsers
useBuiltIns: 'usage',
corejs: '3',
},
],
'@babel/preset-react', // transform JSX to JS
'@babel/preset-typescript',
];
return {
presets,
plugins,
overrides,
};
};