import { compact } from 'lodash' ; import { sync as resolve } from 'resolve' ; import { PluginItem , TransformOptions } from '@babel/core' ; import { shouldEnable } from './utils' ; import getParseOnlyBabelConfigFilled from './parseOnly' ; import { BabelConfigOptionsFilled } from './interface' ; const requireLodashOptimization = ( options ) => { const { uses , mode } = options ; return shouldEnable ( 'lodash' , uses ) && mode === 'production' ; } ; const requireDisplayName = ( options ) => { const { displayName , mode } = options ; return displayName === true || ( displayName === 'auto' && mode === 'development' ) ; } ; export default ( options ) : TransformOptions => { const minimal = getParseOnlyBabelConfigFilled ( options ) ; const { uses , mode } = options ; const plugins = [ requireDisplayName ( options ) && resolve ( '@reskript/babel-plugin-add-react-display-name' ) , shouldEnable ( 'styled-components' , uses ) && [ resolve ( 'babel-plugin-styled-components' ) , { displayName : requireDisplayName ( options ) , minify : mode === 'production' , meaninglessFileNames : [ 'index' ] , } , ] , shouldEnable ( 'emotion' , uses ) && [ resolve ( '@emotion/babel-plugin' ) , { sourceMap : mode === 'development' , autoLabel : 'always' , } , ] , shouldEnable ( 'reflect-metadata' , uses ) && resolve ( 'babel-plugin-transform-typescript-metadata' ) , ... minimal . plugins || [ ] , shouldEnable ( 'antd' , uses ) && [ resolve ( 'babel-plugin-import' ) , { libraryName : 'antd' , libraryDirectory : 'es' , style : true , } , ] , requireLodashOptimization ( options ) && [ resolve ( 'babel-plugin-lodash' ) , { id : [ 'lodash' , 'lodash-decorators' ] , } , ] , ] ; return { presets : minimal . presets , plugins : compact ( plugins ) , } ; } ;