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