const path = require ( 'path' ) ; const webpack = require ( 'webpack' ) ; module . exports = function initCompiler ( { webpackConfig } ) { let pendingCallbacks = [ ] ; const webpackCompiler = webpack ( webpackConfig ) ; new webpack . ProgressPlugin ( { entries : true , modules : false , profile : false , } ) . apply ( webpackCompiler ) ; function isLocalIndexHtmlReady ( ) { return webpackCompiler . outputFileSystem . existsSync ( path . join ( process . cwd ( ) , '//dist//index.html' ) ) ; } function readLocalIndexHtml ( ) { return webpackCompiler . outputFileSystem . readFileSync ( path . join ( process . cwd ( ) , '//dist//index.html' ) , 'utf8' ) ; } function callWhenReady ( cb ) { pendingCallbacks . push ( cb ) ; } function onReady ( ) { if ( isLocalIndexHtmlReady ( ) && pendingCallbacks . length > 0 ) { const cbs = pendingCallbacks ; pendingCallbacks = [ ] ; cbs . forEach ( cb => { cb ( ) ; } ) ; } } webpackCompiler . hooks . done . tap ( 'GravitationalDevServer' , onReady ) ; return { webpackCompiler , isLocalIndexHtmlReady , readLocalIndexHtml , callWhenReady , } ; } ;