vuejs / vue-component-compiler

Compile a single file Vue component into a CommonJS module.
MIT License
342 stars 52 forks source link

Proposal: Hot reload API #52

Closed znck closed 6 years ago

znck commented 6 years ago

The hot reload API offered by webpack, parcel et.el is similar, but there are minute differences which make it impossible to provide implementations for all bundlers out there. Hence, we should make hot API injectable.

What is required in hot reload?

Proposed API:

{
  hot: {
    // 1. Wrap code with a conditional statement, checking if hot API is available or not.
    isHot: (expression: string) => string,
    // 2. Generate code calling `hot.accept` with passed handler function.
    accept: (fn: string) => string,
    // 3. Generate code calling `hot.dispose` with passed handler function.
    dispose: (fn: string) => string
  }
}

Related Issue: #51

yyx990803 commented 6 years ago

Can you give an example of what webpack usage would look like with this API?

yyx990803 commented 6 years ago

BTW, since most of the bundlers that support hot-reload in some way (webpack, parcel, browserify + hmr plugin) share somewhat similar API, we should probably have that as the default implementation, and use it when the hot is omitted (or disabled if hot is false). The API largely exists to make it configurable for the long term.