import { compact } from 'lodash' ; import { sync as resolve } from 'resolve' ; import { PluginItem , TransformOptions } from '@babel/core' ; import { BabelConfigOptionsFilled } from './interface' ; import { shouldEnable } from './utils' ; export default ( options ) : TransformOptions => { const { polyfill , modules , uses } = options ; const presets = [ [ resolve ( '@babel/preset-env' ) , { modules , bugfixes : true , debug : false , useBuiltIns : polyfill ? 'usage' : false , corejs : polyfill ? { version : 3 , proposals : true } : undefined , } , ] , resolve ( '@babel/preset-typescript' ) , [ resolve ( '@babel/preset-react' ) , { runtime : 'automatic' , importSource : shouldEnable ( 'emotion' , uses ) ? '@emotion/react' : 'react' , } , ] , ] ; const plugins = [ [ resolve ( '@babel/plugin-proposal-decorators' ) , { legacy : true } ] , resolve ( '@babel/plugin-proposal-class-properties' ) , resolve ( '@babel/plugin-proposal-do-expressions' ) , resolve ( '@babel/plugin-proposal-export-default-from' ) , resolve ( '@babel/plugin-proposal-export-namespace-from' ) , resolve ( '@babel/plugin-proposal-nullish-coalescing-operator' ) , resolve ( '@babel/plugin-proposal-numeric-separator' ) , resolve ( '@babel/plugin-proposal-optional-chaining' ) , [ resolve ( '@babel/plugin-proposal-pipeline-operator' ) , { proposal : 'minimal' } ] , resolve ( '@babel/plugin-proposal-throw-expressions' ) , resolve ( '@babel/plugin-syntax-dynamic-import' ) , resolve ( '@babel/plugin-syntax-import-meta' ) , ] ; return { plugins , presets : compact ( presets ) , } ; } ;