优化hmr

pull/1/head
yutent 2023-02-12 17:04:19 +08:00
parent b841475b63
commit c9bdc6c2f3
2 changed files with 6 additions and 2 deletions

View File

@ -16,13 +16,17 @@ export const COMMON_HEADERS = {
} }
export const HMR_SCRIPT = ` export const HMR_SCRIPT = `
!(function(){ !(function vue_live_hmr(){
var ws = new WebSocket(\`ws\${location.protocol === 'https:' ? 's' : ''}://\${location.host}/ws-vue-live\`) var ws = new WebSocket(\`ws\${location.protocol === 'https:' ? 's' : ''}://\${location.host}/ws-vue-live\`)
ws.addEventListener('open', function (r) { ws.addEventListener('open', function (r) {
console.log('vue-live hmr ready...') console.log('vue-live hmr ready...')
}) })
ws.addEventListener('close', function(){
setTimeout(vue_live_hmr, 1000)
})
ws.addEventListener('message', function (ev) { ws.addEventListener('message', function (ev) {
var { action, data } = JSON.parse(ev.data) var { action, data } = JSON.parse(ev.data)

View File

@ -1,7 +1,7 @@
{ {
"name": "@bytedo/vue-live", "name": "@bytedo/vue-live",
"type": "module", "type": "module",
"version": "0.1.5", "version": "0.1.6",
"bin": { "bin": {
"vue-live": "index.js" "vue-live": "index.js"
}, },