52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
/**
|
|
* {一些常量}
|
|
* @author yutent<yutent.io@gmail.com>
|
|
* @date 2022/09/06 11:54:56
|
|
*/
|
|
|
|
export const JS_EXP = /<script[^>]*?>([\w\W]*?)<\/script>/
|
|
export const STYLE_EXP = /<style[^>]*?>([\w\W]*?)<\/style>/g
|
|
export const HTML_EXP = /<template[^>]*?>([\w\W]*?)<\/template>/
|
|
|
|
export const CSS_SHEET_EXP =
|
|
/([\w\.,#\-:>\+\~\|\(\)\[\]"'\=\s]+)\{([^\{\}]*?)\}/g
|
|
|
|
export const COMMON_HEADERS = {
|
|
'Cache-Control': 'no-store'
|
|
}
|
|
|
|
export const HMR_SCRIPT = `
|
|
!(function(){
|
|
var ws = new WebSocket(\`ws://\${location.host}/ws-vue-live\`)
|
|
|
|
ws.addEventListener('open', function (r) {
|
|
console.log('vue-live hmr ready...')
|
|
})
|
|
|
|
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)
|
|
document.adoptedStyleSheets[i] = stylesheet
|
|
break
|
|
}
|
|
}
|
|
}
|
|
break
|
|
}
|
|
})
|
|
})()
|
|
`
|