nklayman / vue-cli-plugin-electron-builder

Easily Build Your Vue.js App For Desktop With Electron
https://nklayman.github.io/vue-cli-plugin-electron-builder/
MIT License
4.12k stars 280 forks source link

Hot-Reload not working in background.js dependencies #741

Closed thezzisu closed 4 years ago

thezzisu commented 4 years ago

Describe the bug Hot-Reload wont work when despondencies of background.js changed.

To Reproduce Steps to reproduce the behavior:

// src/background.ts
'use strict'

import path from 'path'
import { app, protocol, BrowserWindow, Tray, Menu, Notification } from 'electron'
import { createProtocol, installVueDevtools } from 'vue-cli-plugin-electron-builder/lib'
import { getConfig } from './common/config'

const isDevelopment = process.env.NODE_ENV !== 'production'

protocol.registerSchemesAsPrivileged([{ scheme: 'app', privileges: { secure: true, standard: true } }])

let win: BrowserWindow | null

function createWindow () {
  ...
}

if (app.requestSingleInstanceLock()) {
  app.on('ready', async () => {
    ... // Install Vue Devtools
    const config = getConfig()
    if (!config.hideOnStart) {
      createWindow()
    }
  })
  ...
} else {
  app.quit()
}
// src/common/config.ts

export function getConfig(){
  ...
}

Edit src/common/config.ts, but the background process wont be reloaded Expected behavior background process should be reloaded after its dependencies updated

Screenshots

Environment (please complete the following information):

nklayman commented 4 years ago

You need to add the file to the mainProcessWatch array in vue.config.js:


// vue.config.js

module.exports = {
  pluginOptions: {
    electronBuilder: {
      // Provide an array of files that, when changed, will recompile the main process and restart Electron
      // Your main process file will be added by default
      mainProcessWatch: ['src/myFile1', 'src/myFile2'],
    }
  }
}
JenuelDev commented 3 years ago

can I do something like this @nklayman image

nklayman commented 3 years ago

@BroJenuel no, glob files are not supported for mainProcessWatch. However, you can add directories to that list and all contents will be watched.

JenuelDev commented 3 years ago

@BroJenuel no, glob files are not supported for mainProcessWatch. However, you can add directories to that list and all contents will be watched.

awesome, thanks a lot <3 more power

g8up commented 1 year ago

delete dist_electron generated by electron:build, and run electron:server, it would reload well when change background.js.