import path from 'path' ; import { compact } from 'lodash' ; import { sync as resolve } from 'resolve' ; import { PluginItem , TransformOptions } from '@babel/core' ; import { fillBabelConfigOptions } from './utils' ; import getParseOnlyBabelConfigFilled from './parseOnly' ; import getTransformBabelConfigFilled from './transform' ; import { BabelConfigOptions , BabelConfigOptionsFilled } from './interface' ; export type { BabelConfigOptions } ; export const getParseOnlyBabelConfig = ( options ? ) : TransformOptions => { return getParseOnlyBabelConfigFilled ( fillBabelConfigOptions ( options ) ) ; } ; export const getTransformBabelConfig = ( input ? ) : TransformOptions => { return getTransformBabelConfigFilled ( fillBabelConfigOptions ( input ) ) ; } ; const requireFileName = ( options ) => { const { mode , hostType } = options ; return mode === 'development' && hostType === 'application' ; } ; export const getBabelConfig = ( input ? ) : TransformOptions => { const options = fillBabelConfigOptions ( input ) ; const { mode , hot , hostType , cwd , srcDirectory } = options ; const transform = getTransformBabelConfig ( options ) ; const requireReactOptimization = mode === 'production' && hostType === 'application' ; const plugins = [ requireFileName ( options ) && [ resolve ( '@reskript/babel-plugin-debug-react-component-file-name' ) , { srcDirectory : path . resolve ( cwd , srcDirectory ) , fullPathPrefix : options . openInEditorPrefix , } , ] , ... transform . plugins || [ ] , requireReactOptimization && resolve ( 'babel-plugin-transform-react-remove-prop-types' ) , hot && [ resolve ( 'react-refresh/babel' ) , { skipEnvCheck : true } ] , ] ; return { presets : transform . presets , plugins : compact ( plugins ) } ; } ;