2022-09-09 10:52:27 +08:00
|
|
|
/**
|
|
|
|
* {一些常量}
|
|
|
|
* @author yutent<yutent.io@gmail.com>
|
|
|
|
* @date 2022/09/06 11:54:56
|
|
|
|
*/
|
|
|
|
|
|
|
|
export const JS_EXP = /<script[^>]*?>([\w\W]*?)<\/script>/
|
2023-02-24 15:45:55 +08:00
|
|
|
export const STYLE_EXP = /<style([^>]*?)>([\w\W]*?)<\/style>/g
|
2023-02-23 00:00:10 +08:00
|
|
|
export const HTML_EXP = /<template[^>]*?>([\w\W]*?)\n<\/template>/
|
2023-03-28 11:39:34 +08:00
|
|
|
export const V_DEEP = /:deep\(([^)]*?)\)/
|
2022-09-09 10:52:27 +08:00
|
|
|
|
2023-02-20 00:41:58 +08:00
|
|
|
export const CSS_SHEET_EXP = /([@\w\.,#\-:>\+\~\|\(\)\[\]"'\=\s]+)\{/g
|
2022-10-18 16:02:29 +08:00
|
|
|
|
2022-09-09 10:52:27 +08:00
|
|
|
export const COMMON_HEADERS = {
|
|
|
|
'Cache-Control': 'no-store'
|
|
|
|
}
|
2023-02-01 10:51:33 +08:00
|
|
|
|
|
|
|
export const HMR_SCRIPT = `
|
2023-02-12 17:04:19 +08:00
|
|
|
!(function vue_live_hmr(){
|
2023-02-08 18:14:06 +08:00
|
|
|
var ws = new WebSocket(\`ws\${location.protocol === 'https:' ? 's' : ''}://\${location.host}/ws-vue-live\`)
|
2023-02-01 10:51:33 +08:00
|
|
|
|
|
|
|
ws.addEventListener('open', function (r) {
|
2023-02-20 00:41:58 +08:00
|
|
|
if(vue_live_hmr.closed){
|
|
|
|
delete vue_live_hmr.closed
|
|
|
|
location.reload()
|
|
|
|
}
|
2023-02-01 10:51:33 +08:00
|
|
|
console.log('vue-live hmr ready...')
|
|
|
|
})
|
2023-02-12 17:04:19 +08:00
|
|
|
|
|
|
|
ws.addEventListener('close', function(){
|
2023-02-20 00:41:58 +08:00
|
|
|
vue_live_hmr.closed = true
|
2023-02-16 15:32:17 +08:00
|
|
|
setTimeout(vue_live_hmr, 2000)
|
2023-02-12 17:04:19 +08:00
|
|
|
})
|
2023-02-01 10:51:33 +08:00
|
|
|
|
|
|
|
ws.addEventListener('message', function (ev) {
|
|
|
|
var { action, data } = JSON.parse(ev.data)
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case 'reload':
|
|
|
|
location.reload()
|
|
|
|
break
|
|
|
|
|
|
|
|
case 'render':
|
|
|
|
{
|
|
|
|
let tmp = [...document.adoptedStyleSheets]
|
|
|
|
for (let i = -1, it; (it = tmp[++i]); ) {
|
|
|
|
if (it.path === data.path) {
|
|
|
|
let stylesheet = new CSSStyleSheet()
|
|
|
|
stylesheet.path = data.path
|
|
|
|
stylesheet.replaceSync(data.content)
|
2023-04-25 11:12:27 +08:00
|
|
|
tmp[i] = stylesheet
|
|
|
|
document.adoptedStyleSheets = tmp
|
2023-02-01 10:51:33 +08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})()
|
|
|
|
`
|