与webpack和电子的外部

时间:2017-07-13 02:29:51

标签: webpack electron

我正在使用React与Webpack和Electron,我正在尝试从渲染器进程中要求遥控器。我的代码正在由Babel + Webpack发布,但是这行代码:

import {remote} from 'electron'

给了我

Uncaught Error: Cannot find module "electron"

我该如何解决这个问题?我知道这个问题是因为电子注入电子模块在webpack不知道的页面的渲染上。

const {remote} = window.require('electron')

工作正常,因为webpack忽略了它。

1 个答案:

答案 0 :(得分:1)

如果您使用的是最新版本的webpack,请在渲染器配置中将目标属性设置为electron-renderer

module.exports = {
 target: 'electron-renderer',
 //... other configurations
}

如果您使用webpack捆绑main(main.js),请在主配置中将目标属性设置为electron-main

module.exports = {
 target: 'electron-main',
 //... other configurations
}
相关问题