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