2018-11-08 22:37:12 +08:00
|
|
|
const presets = [
|
|
|
|
[
|
|
|
|
'@babel/preset-env',
|
|
|
|
{
|
|
|
|
modules: false,
|
2019-03-12 23:48:37 +08:00
|
|
|
// see also zloirock/core-js https://bit.ly/2JLnrgw
|
2019-10-02 23:36:24 +08:00
|
|
|
useBuiltIns: 'usage',
|
2020-11-07 23:42:41 +08:00
|
|
|
corejs: '3.7',
|
2020-03-20 22:19:56 +08:00
|
|
|
// new in babel 7.9.0 https://babeljs.io/blog/2020/03/16/7.9.0
|
2020-06-03 21:44:00 +08:00
|
|
|
bugfixes: true,
|
|
|
|
},
|
2018-11-08 22:37:12 +08:00
|
|
|
],
|
2020-09-23 19:47:08 +08:00
|
|
|
['@babel/preset-react', { runtime: 'automatic' }],
|
2020-06-03 21:44:00 +08:00
|
|
|
'@babel/preset-flow',
|
|
|
|
'@babel/preset-typescript',
|
2018-11-08 22:37:12 +08:00
|
|
|
];
|
|
|
|
|
2020-06-03 21:44:00 +08:00
|
|
|
module.exports = (api) => {
|
2020-01-15 13:07:08 +08:00
|
|
|
// https://babeljs.io/docs/en/config-files#apicache
|
2019-12-20 23:02:10 +08:00
|
|
|
api.cache.using(() => process.env.NODE_ENV);
|
2020-01-15 13:07:08 +08:00
|
|
|
// https://babeljs.io/docs/en/config-files#apienv
|
2019-12-20 23:02:10 +08:00
|
|
|
const isDev = api.env('development');
|
|
|
|
const plugins = [
|
|
|
|
[
|
|
|
|
'@babel/plugin-transform-runtime',
|
|
|
|
{
|
|
|
|
corejs: false,
|
|
|
|
helpers: true,
|
|
|
|
regenerator: true,
|
2020-06-03 21:44:00 +08:00
|
|
|
useESModules: true,
|
|
|
|
},
|
2019-12-20 23:02:10 +08:00
|
|
|
],
|
|
|
|
'@babel/plugin-syntax-dynamic-import',
|
|
|
|
'@babel/plugin-proposal-class-properties',
|
|
|
|
'@babel/plugin-proposal-do-expressions',
|
2020-06-03 21:44:00 +08:00
|
|
|
isDev ? 'react-refresh/babel' : false,
|
2019-12-20 23:02:10 +08:00
|
|
|
].filter(Boolean);
|
2018-11-08 22:37:12 +08:00
|
|
|
return { presets, plugins };
|
|
|
|
};
|