Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
thezzisu opened this issue May 6, 2020 · 5 comments
Closed

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

thezzisu opened this issue May 6, 2020 · 5 comments

Comments

@thezzisu
Copy link

thezzisu commented May 6, 2020

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
Copy link
Owner

nklayman commented May 7, 2020

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'],
    }
  }
}

@nklayman nklayman closed this as completed May 7, 2020
@JenuelDev
Copy link

JenuelDev commented Sep 20, 2021

can I do something like this @nklayman
image

@nklayman
Copy link
Owner

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

@JenuelDev
Copy link

@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
Copy link

g8up commented Dec 1, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants