electron-vue配置问题

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版本需要加多这一行
      enableRemoteModule:true //v9版本 打开remote模块
    }
  })

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
      ],
      ...
    },
    ...
}
posted @ 2021-04-30 17:01  bugSource  阅读(527)  评论(0编辑  收藏  举报