Answers for "js implement hot reload"

0

js implement hot reload

const fs = require('fs')
const child = require('child_process')

// watch the target file
const watcher = fs.watch('app.js')
// create a child process for the target application
let currentChild = child.fork('app.js')

watcher.on('change', () => {
  // we assure we have only one child process at time
  if (currentChild) {
    currentChild.kill()
  }
  // reset the child process
  currentChild = child.fork('app.js')
})
Posted by: Guest on October-15-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language