react/packages/react-devtools-shared/babel.config.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

const chromeManifest = require('../react-devtools-extensions/chrome/manifest.json');
const firefoxManifest = require('../react-devtools-extensions/firefox/manifest.json');
2019-04-27 02:29:51 +08:00
const minChromeVersion = parseInt(chromeManifest.minimum_chrome_version, 10);
const minFirefoxVersion = parseInt(
firefoxManifest.applications.gecko.strict_min_version,
2019-08-14 08:58:03 +08:00
10,
2019-04-27 02:29:51 +08:00
);
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();
let additionalTargets = process.env.BABEL_CONFIG_ADDITIONAL_TARGETS;
if (additionalTargets) {
additionalTargets = JSON.parse(additionalTargets);
for (const target in additionalTargets) {
targets[target] = additionalTargets[target];
}
}
2019-04-27 02:29:51 +08:00
}
const plugins = [
['@babel/plugin-transform-flow-strip-types'],
2019-08-14 08:58:03 +08:00
['@babel/plugin-proposal-class-properties', {loose: false}],
];
if (process.env.NODE_ENV !== 'production') {
plugins.push(['@babel/plugin-transform-react-jsx-source']);
}
2019-04-27 02:29:51 +08:00
return {
plugins,
2019-04-27 02:29:51 +08:00
presets: [
2019-08-14 08:58:03 +08:00
['@babel/preset-env', {targets}],
2019-04-27 02:29:51 +08:00
'@babel/preset-react',
'@babel/preset-flow',
],
};
};