Configuring electron-webpack renderer to work with nodeIntegration: false

你。 提交于 2019-12-10 14:48:36

问题


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?

来源:https://stackoverflow.com/questions/49705639/configuring-electron-webpack-renderer-to-work-with-nodeintegration-false

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!