import { sync as resolve } from 'resolve' ; import { getBabelConfig , BabelConfigOptions } from '@reskript/config-babel' ; import { BuildEntry , warnAndExitOnInvalidFinalizeReturn } from '@reskript/settings' ; import { LoaderFactory } from '../interface' ; const factory = ( entry ) => { const { usage , mode , cwd , srcDirectory , projectSettings : { build , devServer } } = entry ; const { uses , script : { polyfill , displayName } } = build ; const { hot } = devServer ; const babelConfigOptions = { cwd , srcDirectory , mode , polyfill , uses , displayName , hot : usage === 'devServer' ? hot : false , hostType : 'application' , openInEditorPrefix : ':origin/__open_in_editor__?file=' , } ; const internalCreatedBabelConfig = getBabelConfig ( babelConfigOptions ) ; const finalizedBabelConfig = build . script . finalize ( internalCreatedBabelConfig , entry ) ; warnAndExitOnInvalidFinalizeReturn ( finalizedBabelConfig , 'build.script' ) ; return { loader : resolve ( 'babel-loader' ) , options : { ... finalizedBabelConfig , babelrc : false , } , } ; } ; export default factory ;