electron-userland / electron-compile

DEPRECATED: Electron supporting package to compile JS and CSS in Electron applications
1.01k stars 99 forks source link

Vue hot reloading (and a hack to get it working) #281

Open eeror opened 6 years ago

eeror commented 6 years ago

Vue hot reloading doesn't currently work as the module.hot implementation is both incomplete and doesn't follow webpack's API. I've managed to get Vue to hot reload using the hack below, however. The rest is already handled by vueify.

Is there any chance this could end up in the package? I'd be willing to prepare a pull request but I would need some guidance as I'm not sure how the following would fit with the overall architecture.

App.vue:

import install from './install'
install(module)

export default {
  data () {

install.js:

if (!window.__hotData) {
  window.__hotData = {}
  window.__hotDisposeHandlers = {}
}

export default (moduleInstance) => {
  const fileName = moduleInstance.filename

  moduleInstance.hot = {
    accept () {
      moduleInstance.hot.data = window.__hotData[fileName]

      if (!window.__hotDisposeHandlers[fileName]) {
        window.__hot.push(() => {
          const data = window.__hotData[fileName] = {}
          window.__hotDisposeHandlers[fileName](data)
          require(fileName)
        })

        window.__hotDisposeHandlers[fileName] = () => {}
      }
    },
    dispose (disposeHandler) {
      window.__hotDisposeHandlers[fileName] = disposeHandler
    }
  }
}