Fix codeclimate issues in babel.config.js

This commit is contained in:
Pranav Raj Sreepuram 2019-10-22 12:32:45 +05:30
parent 9c22da0ac6
commit cd43b09574

View file

@ -1,43 +1,5 @@
/* eslint-disable global-require */ /* eslint-disable global-require */
const plugins = isTestEnv => [
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');
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 && [
require('@babel/preset-env').default,
{
targets: {
node: 'current',
},
},
],
(isProductionEnv || isDevelopmentEnv) && [
require('@babel/preset-env').default,
{
forceAllTransforms: true,
useBuiltIns: 'entry',
modules: false,
exclude: ['transform-typeof-symbol'],
},
],
].filter(Boolean),
plugins: [
require('babel-plugin-macros'), require('babel-plugin-macros'),
require('@babel/plugin-syntax-dynamic-import').default, require('@babel/plugin-syntax-dynamic-import').default,
isTestEnv && require('babel-plugin-dynamic-import-node'), isTestEnv && require('babel-plugin-dynamic-import-node'),
@ -69,6 +31,49 @@ module.exports = api => {
}, },
], ],
[require('babel-plugin-transform-vue-jsx')], [require('babel-plugin-transform-vue-jsx')],
].filter(Boolean), ];
const presets = (isTestEnv, isProductionEnv, isDevelopmentEnv) => [
isTestEnv && [
require('@babel/preset-env').default,
{
targets: {
node: 'current',
},
},
],
(isProductionEnv || isDevelopmentEnv) && [
require('@babel/preset-env').default,
{
forceAllTransforms: true,
useBuiltIns: 'entry',
modules: false,
exclude: ['transform-typeof-symbol'],
},
],
];
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');
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: presets(isTestEnv, isProductionEnv, isDevelopmentEnv).filter(
Boolean
),
plugins: plugins(isTestEnv).filter(Boolean),
}; };
}; };