electron 安装下载太慢的解决方案
最简单的方法修改为阿里的镜像源即可
- 打开设置
通过以上命令打开npm config edit
.npmrc
文件 - 在文件最后追加
ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/ ELECTRON_BUILDER_BINARIES_MIRROR=https://npm.taobao.org/mirrors/electron-builder-binaries/
- 安装(建议全局安装)
安装electron
框架
安装npm install -g electron
electron
打包程序npm install -g electron-builder
如果安装过程中有类似以下提示
npm ERR! code EPERM
npm ERR! syscall rename
那么需要以管理员模式运行命令安装。
如果build过程中,有以下错误,那么请确保package.json
的devDependencies
字段不能为空。
• electron-builder version=22.11.7 os=10.0.19043
• loaded configuration file=package.json ("build" field)
⨯ Cannot compute electron version from installed node modules - none of the possible electron modules are installed.
See https://github.com/electron-userland/electron-builder/issues/3984#issuecomment-504968246
npm ERR! code ELIFECYCLE
我的解决方案是在package.json
文件中,devDependencies
下加入虚拟的内容。不过只要全局安装了,不用再npm install
了
"devDependencies": {
"electron": "12.0.2",
"electron-builder": "22.8.1"
},
另外我在白云苍狗的壁纸APP上提炼了一个开发框架,这里打包提供下载。
readme.md里面有具体说明
https://gitee.com/mr-joe/electron-exe