mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-30 11:24:21 +01:00
2d0819a26d
The loose option must be the same for @babel/plugin-proposal-class-properties and @babel/preset-env. Official babel docs recommands to disable loose option
91 lines
2.2 KiB
JavaScript
91 lines
2.2 KiB
JavaScript
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');
|
|
const isWebpackDevServer = process.env.WEBPACK_DEV_SERVER;
|
|
|
|
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 && [
|
|
'@babel/preset-env',
|
|
{
|
|
targets: {
|
|
node: 'current'
|
|
},
|
|
modules: 'commonjs'
|
|
},
|
|
'@babel/preset-react'
|
|
],
|
|
(isProductionEnv || isDevelopmentEnv) && [
|
|
'@babel/preset-env',
|
|
{
|
|
forceAllTransforms: true,
|
|
useBuiltIns: 'entry',
|
|
corejs: 3,
|
|
modules: false,
|
|
exclude: ['transform-typeof-symbol']
|
|
}
|
|
],
|
|
[
|
|
'@babel/preset-react',
|
|
{
|
|
development: isDevelopmentEnv || isTestEnv,
|
|
useBuiltIns: true
|
|
}
|
|
],
|
|
['@babel/preset-typescript', { allExtensions: true, isTSX: true }]
|
|
].filter(Boolean),
|
|
plugins: [
|
|
isWebpackDevServer && 'react-refresh/babel',
|
|
'babel-plugin-macros',
|
|
'@babel/plugin-syntax-dynamic-import',
|
|
isTestEnv && 'babel-plugin-dynamic-import-node',
|
|
'@babel/plugin-transform-destructuring',
|
|
[
|
|
'@babel/plugin-proposal-class-properties',
|
|
{
|
|
loose: false
|
|
}
|
|
],
|
|
[
|
|
'@babel/plugin-proposal-object-rest-spread',
|
|
{
|
|
useBuiltIns: true
|
|
}
|
|
],
|
|
[
|
|
'@babel/plugin-transform-runtime',
|
|
{
|
|
helpers: false,
|
|
regenerator: true,
|
|
corejs: false
|
|
}
|
|
],
|
|
[
|
|
'@babel/plugin-transform-regenerator',
|
|
{
|
|
async: false
|
|
}
|
|
],
|
|
isProductionEnv && [
|
|
'babel-plugin-transform-react-remove-prop-types',
|
|
{
|
|
removeImport: true
|
|
}
|
|
]
|
|
].filter(Boolean)
|
|
};
|
|
};
|