2019-03-13 15:31:59 +01:00
|
|
|
module.exports = function(api) {
|
2021-09-16 15:37:53 +02:00
|
|
|
var validEnv = ['development', 'test', 'production']
|
|
|
|
var currentEnv = api.env()
|
|
|
|
var isDevelopmentEnv = api.env('development')
|
|
|
|
var isProductionEnv = api.env('production')
|
|
|
|
var isTestEnv = api.env('test')
|
2019-03-13 15:31:59 +01:00
|
|
|
|
|
|
|
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) +
|
|
|
|
'.'
|
2021-09-16 15:37:53 +02:00
|
|
|
)
|
2019-03-13 15:31:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
presets: [
|
|
|
|
isTestEnv && [
|
2021-09-16 15:37:53 +02:00
|
|
|
'@babel/preset-env',
|
2019-03-13 15:31:59 +01:00
|
|
|
{
|
|
|
|
targets: {
|
|
|
|
node: 'current'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
(isProductionEnv || isDevelopmentEnv) && [
|
2021-09-16 15:37:53 +02:00
|
|
|
'@babel/preset-env',
|
2019-03-13 15:31:59 +01:00
|
|
|
{
|
|
|
|
forceAllTransforms: true,
|
2020-01-30 13:40:06 +01:00
|
|
|
useBuiltIns: 'usage',
|
|
|
|
corejs: 3,
|
2019-03-13 15:31:59 +01:00
|
|
|
modules: false,
|
|
|
|
exclude: ['transform-typeof-symbol']
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
2021-09-16 15:37:53 +02:00
|
|
|
'@babel/preset-react',
|
2019-03-13 15:31:59 +01:00
|
|
|
{
|
|
|
|
development: isDevelopmentEnv || isTestEnv,
|
|
|
|
useBuiltIns: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
].filter(Boolean),
|
|
|
|
plugins: [
|
2021-09-16 15:37:53 +02:00
|
|
|
'babel-plugin-macros',
|
|
|
|
'@babel/plugin-syntax-dynamic-import',
|
|
|
|
isTestEnv && 'babel-plugin-dynamic-import-node',
|
|
|
|
'@babel/plugin-transform-destructuring',
|
2019-03-13 15:31:59 +01:00
|
|
|
[
|
2021-09-16 15:37:53 +02:00
|
|
|
'@babel/plugin-proposal-class-properties',
|
2019-03-13 15:31:59 +01:00
|
|
|
{
|
|
|
|
loose: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
2021-09-16 15:37:53 +02:00
|
|
|
'@babel/plugin-proposal-object-rest-spread',
|
2019-03-13 15:31:59 +01:00
|
|
|
{
|
|
|
|
useBuiltIns: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
2021-09-16 15:37:53 +02:00
|
|
|
'@babel/plugin-proposal-private-methods',
|
|
|
|
{
|
|
|
|
loose: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'@babel/plugin-proposal-private-property-in-object',
|
|
|
|
{
|
|
|
|
loose: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'@babel/plugin-transform-runtime',
|
2019-03-13 15:31:59 +01:00
|
|
|
{
|
|
|
|
helpers: false,
|
|
|
|
regenerator: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
2021-09-16 15:37:53 +02:00
|
|
|
'@babel/plugin-transform-regenerator',
|
2019-03-13 15:31:59 +01:00
|
|
|
{
|
|
|
|
async: false
|
|
|
|
}
|
|
|
|
],
|
|
|
|
isProductionEnv && [
|
2021-09-16 15:37:53 +02:00
|
|
|
'babel-plugin-transform-react-remove-prop-types',
|
2019-03-13 15:31:59 +01:00
|
|
|
{
|
|
|
|
removeImport: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
].filter(Boolean)
|
2021-09-16 15:37:53 +02:00
|
|
|
}
|
|
|
|
}
|