add watcher and server to send change

This commit is contained in:
pengfei.zhou
2019-08-03 10:19:56 +08:00
parent 99b900f2b6
commit e367093a6a
4 changed files with 42 additions and 3 deletions

View File

@@ -1,10 +1,22 @@
var chokidar = require('chokidar')
const chokidar = require('chokidar')
const ws = require('./server')
const fs = require("fs")
require('shelljs/global')
exec('npm run dev', () => {
})
chokidar.watch(process.cwd() + "/build", {
ws.listen(7777)
chokidar.watch(process.cwd() + "/bundle", {
ignored: /(^|[\/\\])\../,
}).on('all', (event, path) => {
console.log(event, path)
console.log('path is ', path)
if (event === 'add' || event === 'change') {
fs.readFile(path, 'utf-8', (error, data) => {
console.log('send data ', data)
ws.connections.forEach(e => {
e.sendText(data)
})
})
}
});