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

HotReload in vMain and disable nodeIntegration errors #3

Open
rospirski opened this issue Mar 31, 2021 · 6 comments
Open

HotReload in vMain and disable nodeIntegration errors #3

rospirski opened this issue Mar 31, 2021 · 6 comments
Labels
possible-enhancement 🌟 This issue could lead to an improvement
Milestone

Comments

@rospirski
Copy link

Hello, I installed your template right now.
I had two difficulties, one is that it does not restart vMain if I change any files, just a hot reload in the renderer.

And another difficulty is that I deactivated "nodeIntegration" and activated "contextIsolation".
And on my renderer console it is giving the error.
Uncaught ReferenceError: require is not defined

I appreciate if you can help me

Obs *: I am Brazilian, I am using google translate, sorry for the typos.

image

@m4heshd
Copy link
Owner

m4heshd commented Mar 31, 2021

Hi @rospirski,

it does not restart vMain if I change any files

Hot reloading is not enabled for the Main process simply because it never works properly. If you try other plugins that provide this feature you'll notice that it's pretty much useless. So I decided not to integrate something that rarely works. But might look more into that in the future.

Uncaught ReferenceError: require is not defined

That's because you have not defined what modules to bundle in. If you disable nodeIntegration you have to make sure that webpack bundles in all the dependencies used in your Renderer process. Just copy those dependency names from your package.json and add them to vRenderer > bundleIn. Like this.

vRenderer: {
  bundleIn: [
    'core-js',
    'vue',
    'vue-router',
    'vuex',
    'my-dependency-1',
    'my-dependency-2'
  ]
}

Post an update once you try it.

@m4heshd m4heshd added the waiting-author-response ⏳ This thread is blocked by waiting for issue/PR author's response label Mar 31, 2021
@rospirski
Copy link
Author

About the hotreload I didn't know it was a problem, it's not something that will disturb me, just a lack of custom.

About the problem with nodeIntegration I did a clean installation of vue3 cli, with vuex, vue router, vue store, css-sass, and just followed the vuelectron installation step.

The installation is completely clean, I just modified electorn-main.js, changing these lines

nodeIntegration: false,
contextIsolation: true,
enableRemoteModule: false,

I uploaded it to a github repository for you to see.

image

image

@rospirski
Copy link
Author

I forgot to post the repository.

https://github.com/rospirski/vuelectron-nodeIntegration

@rospirski rospirski reopened this Mar 31, 2021
@rospirski
Copy link
Author

Hi @rospirski,

it does not restart vMain if I change any files

Hot reloading is not enabled for the Main process simply because it never works properly. If you try other plugins that provide this feature you'll notice that it's pretty much useless. So I decided not to integrate something that rarely works. But might look more into that in the future.

Uncaught ReferenceError: require is not defined

That's because you have not defined what modules to bundle in. If you disable nodeIntegration you have to make sure that webpack bundles in all the dependencies used in your Renderer process. Just copy those dependency names from your package.json and add them to vRenderer > bundleIn. Like this.

vRenderer: {
  bundleIn: [
    'core-js',
    'vue',
    'vue-router',
    'vuex',
    'my-dependency-1',
    'my-dependency-2'
  ]
}

Post an update once you try it.

I think I got a solution, but I hope you validate it.

In "vue.configs.js"

I changed the webpack target from "electron-renderer" to "web".
And now the require error has stopped.

@m4heshd
Copy link
Owner

m4heshd commented Apr 1, 2021

@rospirski I thought about that. I also thought that you could completely remove the externals property if you're gonna avoid nodeIntegration. But it should work without changing the target. Your approach is totally fine since the Electron renderer works exactly like a browser page without node capabilities. I'll look more into this and push some updates to change this behavior. I'll be keeping this issue open for now.

@m4heshd m4heshd added this to the 1.2.4 milestone Apr 1, 2021
@m4heshd m4heshd added possible-enhancement 🌟 This issue could lead to an improvement and removed waiting-author-response ⏳ This thread is blocked by waiting for issue/PR author's response labels Apr 1, 2021
@rospirski
Copy link
Author

const { contextBridge, ipcRenderer } = require('electron')

contextBridge.exposeInMainWorld('api', {
    send: (channel, data) => {
        let validChannels = ['openUrl', 'minimize', 'close', 'openConfigs', 'startUpdateElectron', 'startUpdateClient', 'openClient', 'clientVerify']
        if (validChannels.includes(channel)) {
            ipcRenderer.send(channel, data)
        }
    },
    on: (channel, func) => {
        let validChannels = ['updateMessage', 'openExecError']
        if (validChannels.includes(channel)) {
            ipcRenderer.on(channel, (event, ...args) => func(...args))
        }
    },
})

I'm building a launcher for a game.
With update system.

In the preload I inject only the ipc dependencies I need, and filter the channels. I found this on the internet and that's what I'm using at the moment. Making the renderer part entirely web.

@m4heshd m4heshd modified the milestones: 1.2.4, 1.2.5 Jun 29, 2021
@m4heshd m4heshd modified the milestones: 1.2.5, 1.2.6 Nov 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible-enhancement 🌟 This issue could lead to an improvement
Projects
None yet
Development

No branches or pull requests

2 participants