1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-10 21:24:20 +01:00
fab-manager/babel.config.js

73 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-10-27 09:41:16 +01:00
module.exports = function (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) +
'.'
2020-10-27 09:41:16 +01:00
);
}
const defaultConfigFunc = require('shakapacker/package/babel/preset.js');
const resultConfig = defaultConfigFunc(api);
const changesOnDefault = {
presets: [
[
'@babel/preset-react',
{
development: isDevelopmentEnv || isTestEnv,
useBuiltIns: true
}
2022-03-14 14:52:23 +01:00
]
].filter(Boolean),
plugins: [
'babel-plugin-macros',
'@babel/plugin-syntax-dynamic-import',
isTestEnv && 'babel-plugin-dynamic-import-node',
'@babel/plugin-transform-destructuring',
[
'@babel/plugin-proposal-class-properties',
{
2022-03-14 14:52:23 +01:00
loose: true
}
],
[
'@babel/plugin-proposal-object-rest-spread',
{
useBuiltIns: true
}
],
[
'@babel/plugin-transform-regenerator',
{
async: false
}
],
isProductionEnv && ['babel-plugin-transform-react-remove-prop-types',
{
removeImport: true
}
],
2022-03-15 11:13:03 +01:00
process.env.WEBPACK_SERVE && [
'react-refresh/babel',
{
exclude: 'node_modules/**'
}
]
].filter(Boolean)
2020-10-27 09:41:16 +01:00
};
resultConfig.presets = [...resultConfig.presets, ...changesOnDefault.presets];
resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins];
return resultConfig;
2020-10-27 09:41:16 +01:00
};