Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack 外部与网页和电子_Webpack_Electron - Fatal编程技术网

Webpack 外部与网页和电子

Webpack 外部与网页和电子,webpack,electron,Webpack,Electron,我正在使用React with Webpack和Electron,我试图要求远程渲染器进程。我的代码正在由Babel+Webpack传输,但这行代码: import {remote} from 'electron' 他给了我 Uncaught Error: Cannot find module "electron" 我怎样才能解决这个问题?我知道问题是因为electron在网页的呈现中注入了electron模块,而webpack对此一无所知 const {remote} = window.r

我正在使用React with Webpack和Electron,我试图要求远程渲染器进程。我的代码正在由Babel+Webpack传输,但这行代码:

import {remote} from 'electron'
他给了我

Uncaught Error: Cannot find module "electron"
我怎样才能解决这个问题?我知道问题是因为electron在网页的呈现中注入了electron模块,而webpack对此一无所知

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

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

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

module.exports = {
 target: 'electron-renderer',
 //... other configurations
}
module.exports = {
 target: 'electron-main',
 //... other configurations
}
如果使用webpack绑定main(main.js),请在主配置中将目标属性设置为
electron main

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

试着用电子来代替电子预建。。electron的最新版本以electron的形式发布。@shashi好的,我会试试看,但仍然不起作用@shashi