main
js 52 lines 1.54 KB
Raw
1 const chromeManifest = require('../react-devtools-extensions/chrome/manifest.json');
2 const firefoxManifest = require('../react-devtools-extensions/firefox/manifest.json');
3
4 const minChromeVersion = parseInt(chromeManifest.minimum_chrome_version, 10);
5 const minFirefoxVersion = parseInt(
6 firefoxManifest.browser_specific_settings.gecko.strict_min_version,
7 10,
8 );
9 validateVersion(minChromeVersion);
10 validateVersion(minFirefoxVersion);
11
12 function validateVersion(version) {
13 if (version > 0 && version < 200) {
14 return;
15 }
16 throw new Error('Suspicious browser version in manifest: ' + version);
17 }
18
19 module.exports = api => {
20 const isTest = api.env('test');
21 const targets = {};
22 if (isTest) {
23 targets.node = 'current';
24 } else {
25 targets.chrome = minChromeVersion.toString();
26 targets.firefox = minFirefoxVersion.toString();
27
28 let additionalTargets = process.env.BABEL_CONFIG_ADDITIONAL_TARGETS;
29 if (additionalTargets) {
30 additionalTargets = JSON.parse(additionalTargets);
31 for (const target in additionalTargets) {
32 targets[target] = additionalTargets[target];
33 }
34 }
35 }
36 const plugins = [
37 ['babel-plugin-syntax-hermes-parser'],
38 ['@babel/plugin-transform-flow-strip-types'],
39 ['@babel/plugin-proposal-class-properties', {loose: false}],
40 ];
41 if (process.env.NODE_ENV !== 'production') {
42 plugins.push(['@babel/plugin-transform-react-jsx-source']);
43 }
44 return {
45 plugins,
46 presets: [
47 ['@babel/preset-env', {targets}],
48 '@babel/preset-react',
49 '@babel/preset-flow',
50 ],
51 };
52 };