webpacker.js
function watchCompiler(compiler, options={}){
  let watching = false
  log('Watch Building')
  const startWatchTime = Date.now()
  const watchConfig = { // watch options:
    //aggregateTimeout: 300, // wait so long for more changes
    //poll: true // use polling instead of native watchers
    // pass a number to set the polling interval
  }

  options.onRebuild = options.onRebuild || function(){}

  return new Promise(function(res,rej){  
    //webpack watch functionality
    compiler.watch(watchConfig, function(err,stats){
      if(err)return rej(err)

      if(watching){
        log('Rebuilt '+getServerTime())
        options.onRebuild(stats)
      }else{
        watching = true
        log('Watching '+(Date.now()-startWatchTime)/1000+' seconds')
        res( this )
      }
    });
  })
}
function watchCompiler(compiler, options={}){
  let watching = false
  log('Watch Building')
  const startWatchTime = Date.now()
  const watchConfig = { // watch options:
    //aggregateTimeout: 300, // wait so long for more changes
    //poll: true // use polling instead of native watchers
    // pass a number to set the polling interval
  }

  options.onRebuild = options.onRebuild || function(){}

  return new Promise(function(res,rej){  
    //webpack watch functionality
    compiler.watch(watchConfig, function(err,stats){
      if(err)return rej(err)

      if(watching){
        log('Rebuilt '+getServerTime())
        options.onRebuild(stats)
      }else{
        watching = true
        log('Watching '+(Date.now()-startWatchTime)/1000+' seconds')
        res( this )
      }
    });
  })
}
function watchCompiler ( compiler , options = { } ) { let watching = false log ( 'Watch Building' ) const startWatchTime = Date . now ( ) const watchConfig = { // watch options: //aggregateTimeout: 300, // wait so long for more changes //poll: true // use polling instead of native watchers // pass a number to set the polling interval } options . onRebuild = options . onRebuild || function ( ) { } return new Promise ( function ( res , rej ) { //webpack watch functionality compiler . watch ( watchConfig , function ( err , stats ) { if ( err ) return rej ( err ) if ( watching ) { log ( 'Rebuilt ' + getServerTime ( ) ) options . onRebuild ( stats ) } else { watching = true log ( 'Watching ' + ( Date . now ( ) - startWatchTime ) / 1000 + ' seconds' ) res ( this ) } } ) ; } ) }
use npm watch for file watching
@options{
onRebuild
}
use npm watch for file watching