Electron - 初体验

Electron 的安装

使用 electron-forge 脚手架

> npm install -g electron-forge
    npm WARN deprecated : <3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of 
    npm WARN deprecated : cross-spawn no longer requires a build toolchain, use it instead
    npm WARN deprecated : request has been deprecated, see https://github.com/request/request/issues/3142
    npm WARN deprecated : wrench.js is deprecated! You should check out fs-extra (https://github.com/jprichardson/node-fs-extra) for any operations you were using wrench for. Thanks for all the usage over the years.
    npm WARN deprecated : This module relies on Node.js‘s internals and will break at some point. Do not use it, and update to 
    npm WARN deprecated : Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue

    > electron-forge init my-app
    electron-forge : 无法加载文件 C:\Users\****\AppData\Roaming\npm\electron-forge.ps1,因为在此系统上禁止运行脚本。有关详
    细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
    所在位置 行:1 字符: 1
    + electron-forge init my-app
    + ~~~~~~~~~~~~~~
        + CategoryInfo          : SecurityError: (:) [],PSSecurityException
        + FullyQualifiedErrorId : UnauthorizedAccess

安装过程正常,但是创建项目出现问题,原因是需要开启一个注册表的权限许可

  1. windows 左下搜 powershell,管理员运行
    Electron - 初体验
  2. 按照报错信息处理重新初始化即可
    Electron - 初体验

使用官方推荐的初始化项目包

  1. 克隆示例项目的仓库

    git clone https://github.com/electron/electron-quick-start
  2. 进入这个仓库

    cd electron-quick-start

  3. 安装依赖并运行
    npm install
    npm start

安装过程有一个文件下载很慢

Downloading electron-v9.0.5-win32-x64.zip: [-----------------------------------------------------] 0% ETA: 0.0 seconds  终止批处理操作吗(Y/N)? y

设置单个包的安装地址,将其指向淘宝镜像

npm set ELECTRON_MIRROR=https://npm.taobao.org/mirrors/electron/

继续安装就可以了

Electron - 初体验

看到这个界面就是成功了

Electron - 初体验

相关推荐