-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbabel.config.js
66 lines (61 loc) · 1.71 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
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
const chromeManifest = require('./shells/browser/chrome/manifest.json');
const firefoxManifest = require('./shells/browser/firefox/manifest.json');
const minChromeVersion = parseInt(chromeManifest.minimum_chrome_version, 10);
const minFirefoxVersion = parseInt(
firefoxManifest.applications.gecko.strict_min_version,
10
);
validateVersion(minChromeVersion);
validateVersion(minFirefoxVersion);
function validateVersion(version) {
if (version > 0 && version < 200) {
return;
}
throw new Error('Suspicious browser version in manifest: ' + version);
}
module.exports = api => {
const isTest = api.env('test');
const targets = {};
if (isTest) {
targets.node = 'current';
} else {
targets.chrome = minChromeVersion.toString();
targets.firefox = minFirefoxVersion.toString();
// This targets RN/Hermes.
targets.ie = '11';
}
const plugins = [
['relay'],
['@babel/plugin-proposal-nullish-coalescing-operator'],
['@babel/plugin-proposal-optional-chaining'],
['@babel/plugin-transform-flow-strip-types'],
['@babel/plugin-proposal-class-properties', { loose: false }],
];
if (process.env.NODE_ENV !== 'production') {
plugins.push(['@babel/plugin-transform-react-jsx-source']);
}
return {
plugins,
sourceType: 'unambiguous',
ignore: [/\/node_modules\//],
presets: [
[
'@babel/preset-env',
{
useBuiltIns: 'entry',
targets,
},
],
'@babel/preset-react',
'@babel/preset-flow',
],
};
};