Skip to content

Commit

Permalink
feat: log hmr updates from server
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 10, 2020
1 parent efc853f commit b0713fe
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/node/server/serverPluginHmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export const hmrPlugin: ServerPlugin = ({
needRerender = true
}

let didUpdateStyle = false
const styleId = hash_sum(publicPath)
const prevStyles = prevDescriptor.styles || []
const nextStyles = descriptor.styles || []
Expand All @@ -203,6 +204,7 @@ export const hmrPlugin: ServerPlugin = ({
if (!needReload) {
nextStyles.forEach((_, i) => {
if (!prevStyles[i] || !isEqual(prevStyles[i], nextStyles[i])) {
didUpdateStyle = true
send({
type: 'vue-style-update',
path: publicPath,
Expand All @@ -216,6 +218,7 @@ export const hmrPlugin: ServerPlugin = ({

// stale styles always need to be removed
prevStyles.slice(nextStyles.length).forEach((_, i) => {
didUpdateStyle = true
send({
type: 'style-remove',
path: publicPath,
Expand All @@ -237,6 +240,17 @@ export const hmrPlugin: ServerPlugin = ({
timestamp
})
}

if (needReload || needRerender || didUpdateStyle) {
let updateType = needReload ? `reload` : needRerender ? `template` : ``
if (didUpdateStyle) {
updateType += ` & style`
}
console.log(
chalk.green(`[vite:hmr] `) +
`${path.relative(root, file)} updated. (${updateType})`
)
}
}

function handleJSReload(filePath: string, timestamp: number = Date.now()) {
Expand Down

0 comments on commit b0713fe

Please sign in to comment.