简体   繁体   English

使用 Electron Builder 编译后,Electron 主进程不会加载其他文件

[英]Electron main process not loading other files once compiled with Electron Builder

  • In dev, everything works fine however once I compile my files using Electron Builder the main process no longer loads the index.html file and consequently the renderer.js file.在开发中,一切正常,但是一旦我使用 Electron Builder 编译我的文件,主进程就不再加载index.html文件,因此不再加载renderer.js文件。
  • I have tried using a combination of __dirname as well as relative/absolute file paths but I cannot get it to work我尝试使用__dirname以及相对/绝对文件路径的组合,但我无法让它工作
  • I have created a minimal reproducible example to further explain my point.我创建了一个最小的可重复示例来进一步解释我的观点。

Steps to reproduce重现步骤

  • git clone
  • cd electron-builder-error
  • yarn install
  • yarn webpack
  • yarn dev (works fine)
  • yarn prod (builds fine)
  • Run the installer
  • Open the program and notice that everything is blank

At your main.js在你的main.js

function createWindow(): void {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
      webSecurity: false
    }
  })

  win.loadFile(process.env.NODE_ENV === 'development'? './index.html' : './compiled/index.html' )
}

And you should pass the NODE_ENV variable at your webpapck configuration.您应该在 webpapck 配置中传递NODE_ENV变量。 Normally, this is set as production So when you run as dev without setting NODE_ENV then it won't work.通常,这被设置为production所以当你在没有设置NODE_ENV情况下作为开发者运行时,它将无法工作。


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM