2019-08-30 20:47:31 +00: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 && [
|
2020-11-19 23:35:29 +00:00
|
|
|
'@babel/preset-env',
|
2019-08-30 20:47:31 +00:00
|
|
|
{
|
|
|
|
targets: {
|
|
|
|
node: 'current'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
(isProductionEnv || isDevelopmentEnv) && [
|
2020-11-19 23:35:29 +00:00
|
|
|
'@babel/preset-env',
|
2019-08-30 20:47:31 +00:00
|
|
|
{
|
|
|
|
forceAllTransforms: true,
|
|
|
|
useBuiltIns: 'entry',
|
|
|
|
corejs: 3,
|
|
|
|
modules: false,
|
|
|
|
exclude: ['transform-typeof-symbol']
|
|
|
|
}
|
2021-02-12 15:57:23 +00:00
|
|
|
],
|
|
|
|
['@babel/preset-typescript', { 'allExtensions': true, 'isTSX': true }]
|
2019-08-30 20:47:31 +00:00
|
|
|
].filter(Boolean),
|
|
|
|
plugins: [
|
2020-11-19 23:35:29 +00:00
|
|
|
'babel-plugin-macros',
|
|
|
|
'@babel/plugin-syntax-dynamic-import',
|
|
|
|
isTestEnv && 'babel-plugin-dynamic-import-node',
|
|
|
|
'@babel/plugin-transform-destructuring',
|
2019-08-30 20:47:31 +00:00
|
|
|
[
|
2020-11-19 23:35:29 +00:00
|
|
|
'@babel/plugin-proposal-class-properties',
|
2019-08-30 20:47:31 +00:00
|
|
|
{
|
|
|
|
loose: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
2020-11-19 23:35:29 +00:00
|
|
|
'@babel/plugin-proposal-object-rest-spread',
|
2019-08-30 20:47:31 +00:00
|
|
|
{
|
|
|
|
useBuiltIns: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
2020-11-19 23:35:29 +00:00
|
|
|
'@babel/plugin-transform-runtime',
|
2019-08-30 20:47:31 +00:00
|
|
|
{
|
2020-11-19 23:35:29 +00:00
|
|
|
helpers: false
|
2019-08-30 20:47:31 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
2020-11-19 23:35:29 +00:00
|
|
|
'@babel/plugin-transform-regenerator',
|
2019-08-30 20:47:31 +00:00
|
|
|
{
|
|
|
|
async: false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
].filter(Boolean)
|
|
|
|
}
|
|
|
|
}
|