在Electron + React + Webpack设置中找不到模块“电子”

我正在使用React + Electron + Webpack创build一个应用程序,但是在尝试使用Electron模块时,我收到错误,指出“无法find模块”电子。

我在下面的示例代码中的一个我的React组件:

const shell = window.require("electron").shell; shell.showItemInFolder("C:\\Logs"); 

我提到了与webpack&Electron有关的许多问题,但是没有一个解决scheme似乎适用于我。

当我尝试下面的代码:

 require('electron-prebuilt') 

它让我回到了电子可执行文件的path。

在webpack的configuration中有一个target选项,你需要将它设置为electron 。 喜欢这个:

 var config = { target: 'electron', entry: __dirname + '/main.js', output: { path: __dirname + '/dist/', filename: 'bundle.js' }, ... }; module.exports = config;