【问题标题】:Externals with webpack and electron使用 webpack 和电子的外部
【发布时间】:2017-07-13 02:29:50
【问题描述】:

我正在将 React 与 Webpack 和 Electron 一起使用,并且我正在尝试从渲染器进程中获取远程。我的代码正在被 Babel + Webpack 传递,但是这行代码:

import {remote} from 'electron'

给我

Uncaught Error: Cannot find module "electron"

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

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

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

【问题讨论】:

  • 尝试使用electron而不是electron-prebuilt..最新版本的electron作为electron发布..
  • @shashi 好的,我试试
  • 还是不行@shashi

标签: webpack electron


【解决方案1】:

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

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

如果你使用 webpack 打包 main(main.js),在 main 配置中将 target 属性设置为 electron-main

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

【讨论】:

    猜你喜欢
    • 2015-12-07
    • 2020-03-14
    • 2014-04-27
    • 2017-06-20
    • 2017-10-28
    • 2016-05-09
    • 2018-01-09
    • 1970-01-01
    • 2018-09-24
    相关资源
    最近更新 更多