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

Support nodeIntegration on a per renderer level #1559

Closed
camhart opened this issue Oct 13, 2021 · 1 comment
Closed

Support nodeIntegration on a per renderer level #1559

camhart opened this issue Oct 13, 2021 · 1 comment

Comments

@camhart
Copy link

camhart commented Oct 13, 2021

Is your feature request related to a problem? Please describe.
My application uses multiple renderer processes. Some require nodeIntegration, other's don't. I'd like to disable nodeIntegration from the processes that don't require it. However it appears, according to my current understanding, that that can't be done with this plugin. It seems setting vue.config.js's pluginOptions.electronBuilder.nodeIntegration sets it globally for all renderer processes. Is that correct?

Describe the solution you'd like
Each renderer process should be able to specify whether or not nodeIntegration is enabled for that specific renderer process.

@nklayman
Copy link
Owner

Enabling nodeIntegration per-process at runtime is pretty simple, just replace process.env.ELECTRON_NODE_INTEGRATION with the value you want for that process. Where it gets tricky is with the webpack config.

Renderer builds share the same webpack config, which means they all have the same target. Therefore, you can't use the electron-renderer target, which breaks node's builtin modules (and maybe some other things). What you can do is enable nodeIntegration in the plugin settings, then override the webpack target with a custom chain:

module.exports = {
  pluginOptions: {
    electronBuilder: {
      nodeIntegration: true,
      chainWebpackRendererProcess(config) {
        config.target('web')
      }
    }
  }
}

This will enable native node modules to work like normal, but also allow processes without nodeIntegration to work. However, node's bultin modules (like fs) won't work by default. To get around this, you have to use __non_webpack_require__('package') to import a node builtin. I tested this out and it seems to work fine, although it isn't exactly pretty. Unfortunately, I can't think of a better way. You might be able to set up some fancy webpack config to handle it but I'm not sure how you would do that.

Let me know if this works or if you have any more questions.

@camhart camhart closed this as completed Oct 15, 2021
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

2 participants