菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
448
0

electron-vue配置问题

原创
05/13 14:22
阅读数 87060

1.跨域问题

找到src/main/index.js文件,或全局搜索BrowserWindow,添加代码取消跨域

mainWindow = new BrowserWindow({
    height: 563,
    useContentSize: true,
    width: 1000,
    webPreferences: {
      webSecurity: false // 取消跨域
    }
  })

2.渲染进程出错,出现 ReferenceError: require xxx not defined

同样找到src/main/index.js文件,或全局搜索BrowserWindow,添加代码

mainWindow = new BrowserWindow({
    height: 563,
    useContentSize: true,
    width: 1000,
    webPreferences: {
      webSecurity: false, // 取消跨域
      nodeIntegration: true, // v5版本开始需要加多这一行
      contextIsolation: false // v12版本需要加多这一行
    }
  })

3.使用原生模块出错,出现 but app.allowRendererProcessReuse is true的报错字段

同样找到src/main/index.js文件,添加代码

//v9版本开始,官方推荐在 渲染进程中不使用原生nodejs 模块
app.allowRendererProcessReuse = false;

4. NODE_MODULE 版本不匹配

npm install --save-dev electron-rebuild

./node_modules/.bin/electron-rebuild

5.设置打包资源路径

打包后的资源文件夹会复制到文件的resources中

// package.json
{
    ...
    "build": {
      ...
      "extraResources": [
        {
          "from": "static/", 
          "to": "static/"
        }
        // 可以移动多个文件夹,from-to
      ],
      ...
    },
    ...
}

发表评论

0/200
448 点赞
0 评论
收藏
为你推荐 换一批