2022-03-31 12:07:52 +02:00
|
|
|
module.exports = function (api) {
|
|
|
|
var validEnv = ['development', 'test', 'production'];
|
|
|
|
var currentEnv = api.env();
|
|
|
|
var isDevelopmentEnv = api.env('development');
|
|
|
|
var isProductionEnv = api.env('production');
|
|
|
|
var isTestEnv = api.env('test');
|
|
|
|
|
|
|
|
if (!validEnv.includes(currentEnv)) {
|
|
|
|
throw new Error(
|
|
|
|
'Please specify a valid `NODE_ENV` or ' +
|
|
|
|
'`BABEL_ENV` environment variables. Valid values are "development", ' +
|
|
|
|
'"test", and "production". Instead, received: ' +
|
|
|
|
JSON.stringify(currentEnv) +
|
|
|
|
'.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
presets: [
|
|
|
|
isTestEnv && [
|
|
|
|
'@babel/preset-env',
|
|
|
|
{
|
|
|
|
targets: {
|
|
|
|
node: 'current'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
(isProductionEnv || isDevelopmentEnv) && [
|
|
|
|
'@babel/preset-env',
|
|
|
|
{
|
|
|
|
forceAllTransforms: true,
|
|
|
|
useBuiltIns: 'usage',
|
|
|
|
corejs: 3,
|
|
|
|
modules: false,
|
|
|
|
exclude: ['transform-typeof-symbol']
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'@babel/preset-react',
|
|
|
|
{
|
|
|
|
development: isDevelopmentEnv || isTestEnv,
|
|
|
|
useBuiltIns: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
['@babel/preset-typescript', { allExtensions: true, isTSX: true }]
|
|
|
|
].filter(Boolean),
|
|
|
|
plugins: [
|
|
|
|
'babel-plugin-macros',
|
|
|
|
'@babel/plugin-syntax-dynamic-import',
|
|
|
|
isTestEnv && 'babel-plugin-dynamic-import-node',
|
|
|
|
'@babel/plugin-transform-destructuring',
|
2022-04-20 11:14:48 +02:00
|
|
|
['@babel/plugin-transform-typescript', { allowDeclareFields: true }],
|
2022-03-31 12:07:52 +02:00
|
|
|
[
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
|
|
|
{
|
|
|
|
loose: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'@babel/plugin-proposal-object-rest-spread',
|
|
|
|
{
|
|
|
|
useBuiltIns: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'@babel/plugin-proposal-private-methods',
|
|
|
|
{
|
|
|
|
loose: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'@babel/plugin-proposal-private-property-in-object',
|
|
|
|
{
|
|
|
|
loose: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'@babel/plugin-transform-runtime',
|
|
|
|
{
|
|
|
|
helpers: false,
|
|
|
|
regenerator: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'@babel/plugin-transform-regenerator',
|
|
|
|
{
|
|
|
|
async: false
|
|
|
|
}
|
|
|
|
],
|
|
|
|
isProductionEnv && [
|
|
|
|
'babel-plugin-transform-react-remove-prop-types',
|
|
|
|
{
|
|
|
|
removeImport: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
].filter(Boolean)
|
|
|
|
};
|
|
|
|
};
|