vue打包exe之electron-quick-start的npm install 报错
- 1、github地址
- 2、问题
- 3、解决
- 4、其他(打包exe)
- 参考
1、github地址
https://github.com/electron/electron-quick-start
2、问题
我使用的pnpm install
正常安装,执行npm start
提示错误
3、解决
在package.json
文件中加入
"scripts": {"postinstall": "node node_modules/electron/install.js"},"config": {"electron": {"mirror": "https://registry.npmmirror.com/-/binary/electron/"}}
示例:
{"name": "electron-quick-start","version": "1.0.0","description": "A minimal Electron application","main": "main.js","scripts": {"start": "electron .","postinstall": "node node_modules/electron/install.js"},"repository": "https://github.com/electron/electron-quick-start","keywords": ["Electron","quick","start","tutorial","demo"],"author": "GitHub","license": "CC0-1.0","devDependencies": {"electron": "^32.1.2"},"config": {"electron": {"mirror": "https://registry.npmmirror.com/-/binary/electron/"}}}
4、其他(打包exe)
安裝打包插件:npm i electron-packager --save-dev
在package.json
的scripts
标签添加
"packager": "electron-packager ./ hello --out=release --platform=win32 --arch=x64 --overwrite --download.mirrorOptions.mirror=https://npm.taobao.org/mirrors/electron/ --ignore=node_modules"
参数解释:
命令解释如下:
-
./ 表示项目目录是当前目录
-
hello 表示生成exe的名称
-
–platform=win32 表示运行时是windows
-
–out=release 表示生成目录是当前目录下的release 目录
-
–arch=x64 表示是64位平台
-
–overwrite 表示新生成的覆盖老的
-
–download… 表示依赖包采用国内的加速网络下载
-
–ignore 表示忽略node_modules的部分包版本,用来解决报错: This normally means that either you have deleted this package already somehow (check your
ignore settings if using electron-packager). Or your module
installation failed.
示例:
{"name": "electron-quick-start","version": "1.0.0","description": "A minimal Electron application","main": "main.js","scripts": {"start": "electron .","postinstall": "node node_modules/electron/install.js","packager": "electron-packager ./ hello --out=release --platform=win32 --arch=x64 --overwrite --download.mirrorOptions.mirror=https://npm.taobao.org/mirrors/electron/ --ignore=node_modules"},"repository": "https://github.com/electron/electron-quick-start","keywords": ["Electron","quick","start","tutorial","demo"],"author": "GitHub","license": "CC0-1.0","devDependencies": {"electron": "^32.1.2","electron-packager": "^17.1.2"},"config": {"electron": {"mirror": "https://registry.npmmirror.com/-/binary/electron/"}}
}
修改完配置,执行命令:
npm run packager
参考
https://juejin.cn/post/7084628134309396494
https://blog.csdn.net/dong_beijing/article/details/130461361
https://www.jb51.net/javascript/3178779pj.htm
https://www.jb51.net/javascript/3077301ir.htm