客户相关部门,不想要线上的访问,只给本地电脑单机系统,所以本地运行前端和后端的程序,这边前端我按以往经验打包成exe文件,发现npm run build项目构建失败,卡了几天,找了很多原因才发现是镜像源过期的原因。顺便写一下项目打包桌面应用exe的步骤和方法。
打包成exe文件步骤
可参考别人的这个文章链接:
一、在项目目录npm run build项目构建成功后,
二、新建一个文件夹,然后把build构建后的dist文件下的所有文件拉到新建打包文件夹下(dist目录下的,不要把整个dist拉过去),
三、然后再新建package.json,
这是原来的写法
{
"name": "deskApp",
"version": "1.0.0",
"description": "",
"main": "index.html",
"window": {
"title": "桌面应用",
"icon": "",
"width": 800,
"height": 600,
"toolbar": false,
"frame": true,
"resizable": true,
"position": "center",
"transparent": false,
"show": true
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dist": "build --tasks win-x86,win-x64 --mirror https://npm.taobao.org/mirrors/nwjs/ .",
"start": "run --x86 --mirror https://npm.taobao.org/mirrors/nwjs/ ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"nwjs-builder-phoenix": "^1.15.0"
},
"build": {
"nwVersion": "0.27.5"
}
}
因为我把镜像修改了,在这里也需要修改,只需修改scripts相对应的镜像地址即可,修改后是:
{
"name": "deskApp",
"version": "1.0.0",
"description": "",
"main": "index.html",
"window": {
"title": "桌面应用",
"icon": "",
"width": 800,
"height": 600,
"toolbar": false,
"frame": true,
"resizable": true,
"position": "center",
"transparent": false,
"show": true
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dist": "build --tasks win-x86,win-x64 --mirror https://npmmirror.com/mirrors/nwjs/ .",
"start": "run --x86 --mirror https://npmmirror.com/mirrors/nwjs/ ."
},
"author": "",
"license": "ISC",
"devDependencies": {
"nwjs-builder-phoenix": "^1.15.0"
},
"build": {
"nwVersion": "0.27.5"
}
}
四、然后就可以安装完依赖后,再打包了
npm install
npm run dist
淘宝镜像切换
然后再说下,旧版本的淘宝镜像,npm run build,和npm install,一直失败,出现npm sill idealTree buildDeps和卡在idealTree:isp-bms: sill idealTree buildDeps等等问题,原本确实不知道原因,那时候堆了几个项目,把我搞晕了,然后不管去搞别的项目了,几天后被同事告知是镜像源的问题。
我是直接输入以下这条命令就解决了,换另外的镜像
npm config set registry https://registry.npmmirror.com
以下是相关的操作命令和镜像
查看当前镜像地址:npm config get registry;
更换镜像地址(例如):npm config set registry https://registry.npm.taobao.org;(已过期)
(我原本就是这个,淘宝镜像原地址2024年1月22日已过期,所以导致这次问题的出现。)
常用的镜像网址:
npm 官方原始镜像网址是:https://registry.npmjs.org/
淘宝最新 NPM 镜像:https://registry.npmmirror.com
阿里云 NPM 镜像:https://npm.aliyun.com
华为云 NPM 镜像:https://mirrors.huaweicloud.com/repository/npm/
腾讯云 NPM 镜像:https://mirrors.cloud.tencent.com/npm/
网易 NPM 镜像:https://mirrors.163.com/npm/
清华大学开源镜像站:https://mirrors.tuna.tsinghua.edu.cn/
中科院大学开源镜像站:http://mirrors.ustc.edu.cn/