2020-06-09 electron 一些问题和开发前的准备

  • electron、electron-packager慢的问题
export ELECTRON_MIRROR=https://npm.taobao.org/mirrors/electron/
export ELECTRON_CUSTOM_DIR=<CURRENT_VERSION>
  • js 不运行
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-0ueXKeM6/XPcQ+fZ5z5+evQaq4i+TxvOonmAh2jjDJM='), or a nonce ('nonce-...') is required to enable inline execution.

修改html 代码

    <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src * 'unsafe-inline'">
    <meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src * 'unsafe-inline'">
  • 引入 jquery
<script>window.$ = window.jQuery = require("./js/jquery-3.5.1.min")</script>
  • html require 出错 nodeIntegration: true
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
      preload: path.join(__dirname, 'preload.js')
    }
  })
  • 开启浏览器调试模式
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
      preload: path.join(__dirname, 'preload.js')
    }
  })

  mainWindow.webContents.openDevTools()

然后就可以开心地搞html啦!!!

参考文献:
https://www.jianshu.com/p/520934cea5ee

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容