import { webpack , webpackConfig } from '../../bundler/webpack' ; import compiling from '../../utilities/compiling' ; import { BalmEntry , Configuration , BalmError } from '@balm-core/index' ; class WebpackTask extends BalmJS . BalmTask { constructor ( ) { super ( 'webpack' ) ; } recipe ( input ? , output ? , customOptions = { } , fn ? ) { const balmBundler = ( callback ) : void => { this . init ( input || BalmJS . config . scripts . entry , output ) ; const isHook = ! ! input ; compiling . start ( ) ; BalmJS . webpackCompiler = webpack ( webpackConfig ( this . input , this . output , customOptions , isHook ) , ( error , stats ) : void => { compiling . stop ( ) ; const scriptLogLevel = stats . hasErrors ( ) ? BalmJS . LogLevel . Error : stats . hasWarnings ( ) ? BalmJS . LogLevel . Warn : BalmJS . LogLevel . Info ; if ( BalmJS . config . logs . level <= scriptLogLevel ) { console . log ( stats . toString ( BalmJS . config . scripts . stats ) ) ; } fn && fn ( ) ; callback ( ) ; } ) ; } ; return balmBundler ; } get fn ( ) : Function { return this . recipe ( ) ; } } export default WebpackTask ;