Configuring electron-webpack renderer to work with nodeIntegration: false
Asked Answered
S

1

12

I'm attempting to configure electron-webpack's renderer build settings so that they work in a browser window set up with nodeIntegration set to false. This means that node APIs aren't available, which is causing the following problems:

  • webpack seems to be assuming that there is an implementation of require already available so isn't including its own in the produced bundle, but instead is simply adding the bundled definitions into module.exports (causing an error that module isn't defined when the bundle is loaded)

  • html-webpack-plugin is being used to produce the index.html file, and is adding <script>require("source-map-support/source-map-support.js").install()</script> to the output, before the bundle is loaded. This line needs to be moved to after the bundle load line, but don't see any way of doing this.

I've tried setting up the following in my package.json:

"electronWebpack": {
  "renderer": {
    "webpackConfig": "renderer.additions.webpack.js"
  }
}

with the renderer.additions.webpack.js file containing:

module.exports = {
    target: 'web',          // node integration is turned off, so use standard web settings.
    externals: ['electron'] // do not rely on ability to load code externally: only specifically known-preloaded modules are to be excluded from the package
}

but this doesn't seem to have changed anything at all. Any suggestions how to make this work?

Schmid answered 7/4, 2018 at 8:56 Comment(2)
Any solution? I have the same problem.Ravel
found this gist gist.github.com/earksiinni/053470a04defc6d7dfaacd5e5a073b15 but it doesn't help when compiling for productionGooseneck
T
0

If I'm understanding correctly, electron-webpack is a template used to connect Electron apps with Webpack. It seems this project is in maintenance mode and isn't active right now.

I've created a template of Electron and Webpack (albeit a few versions out of date currently with the newest version of the Electron framework) that still works and can be used as a starting point. There are a lot of files involved in setting up this connection, more-so than would be helpful in this stackoverflow answer, so instead I'll point you to the repo: secure-electron-template.

Tearful answered 30/10, 2023 at 3:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.