2019-08-21 16:07:06 +00:00
|
|
|
/* eslint-disable global-require */
|
|
|
|
|
|
|
|
module.exports = api => {
|
|
|
|
const validEnv = ['development', 'test', 'production'];
|
|
|
|
const currentEnv = api.env();
|
|
|
|
const isDevelopmentEnv = api.env('development');
|
|
|
|
const isProductionEnv = api.env('production');
|
|
|
|
const isTestEnv = api.env('test');
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
if (!validEnv.includes(currentEnv)) {
|
|
|
|
throw new Error(
|
2019-08-21 16:07:06 +00:00
|
|
|
`${'Please specify a valid `NODE_ENV` or ' +
|
2019-08-14 09:48:44 +00:00
|
|
|
'`BABEL_ENV` environment variables. Valid values are "development", ' +
|
2019-08-21 16:07:06 +00:00
|
|
|
'"test", and "production". Instead, received: '}${JSON.stringify(
|
|
|
|
currentEnv
|
|
|
|
)}.`
|
|
|
|
);
|
2019-08-14 09:48:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
presets: [
|
|
|
|
isTestEnv && [
|
|
|
|
require('@babel/preset-env').default,
|
|
|
|
{
|
|
|
|
targets: {
|
2019-08-21 16:07:06 +00:00
|
|
|
node: 'current',
|
|
|
|
},
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
],
|
|
|
|
(isProductionEnv || isDevelopmentEnv) && [
|
|
|
|
require('@babel/preset-env').default,
|
|
|
|
{
|
|
|
|
forceAllTransforms: true,
|
|
|
|
useBuiltIns: 'entry',
|
|
|
|
corejs: 3,
|
|
|
|
modules: false,
|
2019-08-21 16:07:06 +00:00
|
|
|
exclude: ['transform-typeof-symbol'],
|
|
|
|
},
|
|
|
|
],
|
2019-08-14 09:48:44 +00:00
|
|
|
].filter(Boolean),
|
|
|
|
plugins: [
|
|
|
|
require('babel-plugin-macros'),
|
|
|
|
require('@babel/plugin-syntax-dynamic-import').default,
|
|
|
|
isTestEnv && require('babel-plugin-dynamic-import-node'),
|
|
|
|
require('@babel/plugin-transform-destructuring').default,
|
|
|
|
[
|
|
|
|
require('@babel/plugin-proposal-class-properties').default,
|
|
|
|
{
|
2019-08-21 16:07:06 +00:00
|
|
|
loose: true,
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
require('@babel/plugin-proposal-object-rest-spread').default,
|
|
|
|
{
|
2019-08-21 16:07:06 +00:00
|
|
|
useBuiltIns: true,
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
require('@babel/plugin-transform-runtime').default,
|
|
|
|
{
|
|
|
|
helpers: false,
|
|
|
|
regenerator: true,
|
2019-08-21 16:07:06 +00:00
|
|
|
corejs: false,
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
require('@babel/plugin-transform-regenerator').default,
|
|
|
|
{
|
2019-08-21 16:07:06 +00:00
|
|
|
async: false,
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
],
|
2019-08-21 16:07:06 +00:00
|
|
|
[require('babel-plugin-transform-vue-jsx')],
|
|
|
|
].filter(Boolean),
|
|
|
|
};
|
|
|
|
};
|