2018-09-14 16:59:48 +01:00
|
|
|
module.exports = (api) => {
|
|
|
|
const env = api.env();
|
|
|
|
|
2019-12-02 12:38:53 +00:00
|
|
|
const reactOptions = {
|
|
|
|
development: false,
|
2023-05-23 09:52:27 +01:00
|
|
|
runtime: 'automatic',
|
2019-12-02 12:38:53 +00:00
|
|
|
};
|
|
|
|
|
2018-09-14 16:59:48 +01: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 15:28:14 +01:00
|
|
|
include: [
|
2023-05-31 08:36:43 +01:00
|
|
|
'transform-numeric-separator',
|
2023-06-14 08:22:54 +01:00
|
|
|
'transform-optional-chaining',
|
|
|
|
'transform-nullish-coalescing-operator',
|
|
|
|
'transform-class-properties',
|
2023-05-03 15:28:14 +01:00
|
|
|
],
|
2018-09-14 16:59:48 +01:00
|
|
|
};
|
|
|
|
|
2023-10-31 10:55:13 +00:00
|
|
|
const plugins = [
|
|
|
|
['formatjs'],
|
|
|
|
'preval',
|
|
|
|
];
|
2018-09-14 16:59:48 +01:00
|
|
|
|
|
|
|
switch (env) {
|
|
|
|
case 'production':
|
2023-10-31 10:55:13 +00:00
|
|
|
plugins.push(...[
|
2018-09-14 16:59:48 +01: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 16:59:48 +01:00
|
|
|
case 'development':
|
2019-12-02 12:38:53 +00:00
|
|
|
reactOptions.development = true;
|
2018-09-14 16:59:48 +01: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 16:59:48 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-10-31 10:55:13 +00:00
|
|
|
const config = {
|
|
|
|
presets: [
|
|
|
|
'@babel/preset-typescript',
|
|
|
|
['@babel/react', reactOptions],
|
|
|
|
['@babel/env', envOptions],
|
|
|
|
],
|
|
|
|
plugins,
|
|
|
|
overrides: [
|
|
|
|
{
|
2024-07-24 09:13:09 +01:00
|
|
|
test: [/tesseract\.js/, /fuzzysort\.js/],
|
2023-10-31 10:55:13 +00:00
|
|
|
presets: [
|
|
|
|
['@babel/env', { ...envOptions, modules: 'commonjs' }],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2018-09-14 16:59:48 +01:00
|
|
|
return config;
|
|
|
|
};
|