2018-09-14 15:59:48 +00:00
|
|
|
module.exports = (api) => {
|
|
|
|
const env = api.env();
|
|
|
|
|
2019-12-02 12:38:53 +00:00
|
|
|
const reactOptions = {
|
|
|
|
development: false,
|
2023-05-23 08:52:27 +00:00
|
|
|
runtime: 'automatic',
|
2019-12-02 12:38:53 +00:00
|
|
|
};
|
|
|
|
|
2018-09-14 15:59:48 +00:00
|
|
|
const envOptions = {
|
2023-10-31 10:55:13 +00:00
|
|
|
useBuiltIns: "usage",
|
|
|
|
corejs: { version: "3.30" },
|
2019-12-02 12:38:53 +00:00
|
|
|
debug: false,
|
2023-05-03 14:28:14 +00:00
|
|
|
include: [
|
2023-05-31 07:36:43 +00:00
|
|
|
'transform-numeric-separator',
|
2023-06-14 07:22:54 +00:00
|
|
|
'transform-optional-chaining',
|
|
|
|
'transform-nullish-coalescing-operator',
|
|
|
|
'transform-class-properties',
|
2023-05-03 14:28:14 +00:00
|
|
|
],
|
2018-09-14 15:59:48 +00:00
|
|
|
};
|
|
|
|
|
2023-10-31 10:55:13 +00:00
|
|
|
const plugins = [
|
|
|
|
['formatjs'],
|
|
|
|
'preval',
|
|
|
|
];
|
2018-09-14 15:59:48 +00:00
|
|
|
|
|
|
|
switch (env) {
|
|
|
|
case 'production':
|
2023-10-31 10:55:13 +00:00
|
|
|
plugins.push(...[
|
2018-09-14 15:59:48 +00:00
|
|
|
'lodash',
|
|
|
|
[
|
|
|
|
'transform-react-remove-prop-types',
|
|
|
|
{
|
|
|
|
mode: 'remove',
|
|
|
|
removeImport: true,
|
|
|
|
additionalLibraries: [
|
|
|
|
'react-immutable-proptypes',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
'@babel/transform-react-inline-elements',
|
|
|
|
[
|
|
|
|
'@babel/transform-runtime',
|
|
|
|
{
|
|
|
|
helpers: true,
|
|
|
|
regenerator: false,
|
|
|
|
useESModules: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
break;
|
2023-10-31 10:55:13 +00:00
|
|
|
|
2018-09-14 15:59:48 +00:00
|
|
|
case 'development':
|
2019-12-02 12:38:53 +00:00
|
|
|
reactOptions.development = true;
|
2018-09-14 15:59:48 +00:00
|
|
|
envOptions.debug = true;
|
2023-11-06 10:24:41 +00:00
|
|
|
|
|
|
|
// We need Babel to not inject polyfills in dev, as this breaks `preval` files
|
|
|
|
envOptions.useBuiltIns = false;
|
|
|
|
envOptions.corejs = undefined;
|
2018-09-14 15:59:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-10-31 10:55:13 +00:00
|
|
|
const config = {
|
|
|
|
presets: [
|
|
|
|
'@babel/preset-typescript',
|
|
|
|
['@babel/react', reactOptions],
|
|
|
|
['@babel/env', envOptions],
|
|
|
|
],
|
|
|
|
plugins,
|
|
|
|
overrides: [
|
|
|
|
{
|
|
|
|
test: /tesseract\.js/,
|
|
|
|
presets: [
|
|
|
|
['@babel/env', { ...envOptions, modules: 'commonjs' }],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2018-09-14 15:59:48 +00:00
|
|
|
return config;
|
|
|
|
};
|