debug by pass reload

This commit is contained in:
王劲鹏 2019-12-11 15:14:29 +08:00
parent 7981ff0851
commit 063bfa79c2
2 changed files with 10 additions and 3 deletions

View File

@ -2,18 +2,18 @@ const ws = require('nodejs-websocket')
const { exec, spawn } = require('child_process')
const fs = require('fs')
var server
var contextId = null
var clientConnection = null
var debuggerConnection = null
const createServer = () => {
let server = ws.createServer(connection => {
server = ws.createServer(connection => {
console.log('connected', connection.headers.host)
if (connection.headers.host.startsWith("localhost")) {
console.log("debugger " + connection.key + " attached to dev kit")
debuggerConnection = connection
clientConnection.sendText(JSON.stringify({
cmd: 'SWITCH_TO_DEBUG',
contextId: contextId
@ -30,7 +30,8 @@ const createServer = () => {
switch(resultObject.cmd) {
case 'DEBUG':
clientConnection = connection
server.debugging = true
console.log("enter debugging")
contextId = resultObject.data.contextId
let projectHome = '.'
@ -56,6 +57,8 @@ const createServer = () => {
})
connection.on('close', function (code) {
console.log('close: code = ' + code, connection.key)
console.log("quit debugging")
server.debugging = false
})
connection.on('error', function (code) {
console.log('error', code)

View File

@ -13,6 +13,10 @@ setTimeout(() => {
chokidar.watch(process.cwd() + "/bundle", {
ignored: /(^|[\/\\])\../,
}).on('change', (path) => {
if (ws.debugging) {
console.log("debugging, hot reload by pass")
return
}
fs.readFile(path, 'utf-8', (error, data) => {
if (!path.endsWith('.map')) {
console.log('File change:', path)