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

nodeIntegration and multiple windows #21

Open
johnlindquist opened this issue Jan 5, 2023 · 5 comments
Open

nodeIntegration and multiple windows #21

johnlindquist opened this issue Jan 5, 2023 · 5 comments

Comments

@johnlindquist
Copy link

Electron can have multiple BrowserWindow instances. Each of them can configure webPreferences and have different settings for nodeIntegration.

Since nodeIntegration is "per window", I don't know if it makes sense to have a global build setting for nodeIntegration.

@caoxiemeihao
Copy link
Member

caoxiemeihao commented Jan 6, 2023

https://github.com/electron-vite/vite-plugin-electron-renderer#config-presets-opinionated
image

vite-plugin-electron-renderer just does some initialization configurations, but they are not mandatory and user configurations have higher priority.
If the user provides a corresponding configuration, the user configuration is used first.


By default Vite's configuration will take effect for each BrowserWindow.
Does your application have multiple HTML files as entry points?
for your application? For example foo.html, bar.html, baz.html.


Multiple BrowserWindow need to be set with different webPreferences then they need to correspond to multiple config files, which may require the use of the Vite's JavaScript API.

e.g.

// scripts/build-renderer.mjs
import { build } from 'vite'
import renderer from 'vite-plugin-electron-renderer'

// foo.html
build({
  plugins: [
    renderer({ nodeIntegration: true }), // Enabled nodeIntegration
  ],
  build: {
    rollupOptions: {
      input: 'foo.html',
    },
  },
})

// bar.html
build({
  plugins: [
    renderer(), // Disable nodeIntegration
  ],
  build: {
    rollupOptions: {
      input: 'bar.html',
    },
  },
})

// -------------------------------------------------------------

// scripts/serve-renderer.mjs
// TODO: something

If this is how you imagine it, I can try to provide a boilerplate project that can have separate webPreferences.nodeIntegration for BrowserWindow.

@caoxiemeihao
Copy link
Member

caoxiemeihao commented Feb 5, 2023

Here 👉 multiple-window

@johnlindquist
Copy link
Author

@caoxiemeihao Awesome! Sorry I've been quiet recently. I had a huge influx of Script Kit users and haven't been able to focus on the vite branch like I need to 😅

I promise to get back to it soon!

@Andrew-web-coder
Copy link

@caoxiemeihao Where did that example go?

@caoxiemeihao
Copy link
Member

@Andrew-web-coder updated

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

3 participants