Skip to content

Commit

Permalink
refactor(hmr): pass context object to handleHotUpdate plugin hook
Browse files Browse the repository at this point in the history
instead of multiple args

BREAKING CHANGE: `handleHotUpdate` plugin hook now receives a single
`HmrContext` argument instead of multiple args.
  • Loading branch information
yyx990803 committed Jan 2, 2021
1 parent d18e950 commit 6c26125
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions packages/plugin-vue/src/handleHotUpdate.ts
Expand Up @@ -6,19 +6,19 @@ import {
setPrevDescriptor
} from './utils/descriptorCache'
import { getResolvedScript, setResolvedScript } from './script'
import { ModuleNode, ViteDevServer } from 'vite'
import { ModuleNode, HmrContext } from 'vite'

const debug = _debug('vite:hmr')

/**
* Vite-specific HMR handling
*/
export async function handleHotUpdate(
file: string,
modules: ModuleNode[],
read: () => string | Promise<string>,
server: ViteDevServer
): Promise<ModuleNode[] | void> {
export async function handleHotUpdate({
file,
modules,
read,
server
}: HmrContext): Promise<ModuleNode[] | void> {
const prevDescriptor = getDescriptor(file, false)
if (!prevDescriptor) {
// file hasn't been requested yet (e.g. async component)
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-vue/src/index.ts
Expand Up @@ -65,11 +65,11 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {
return {
name: 'vite:vue',

handleHotUpdate(file, mods, read, server) {
if (!filter(file)) {
handleHotUpdate(ctx) {
if (!filter(ctx.file)) {
return
}
return handleHotUpdate(file, mods, read, server)
return handleHotUpdate(ctx)
},

config(config) {
Expand Down

0 comments on commit 6c26125

Please sign in to comment.