其他私有源:Nexus
npm install -g verdaccio
# 检查安装是否成功
verdaccio --version
# 2.1启动
verdaccio
# 2.2关闭
pkill -f verdaccio
# 2.3访问地址
http address - http://localhost:4873/ - verdaccio 6.x.x
# 2.4读取权限
sudo chmod -R 777 ./storage
# 2.5修改启动端口为:8080
verdaccio --listen 0.0.0.0:8080
# 2.6 配置文件路径
# 2.6.1
Linux/macOS: ~/.config/verdaccio/config.yaml
# 2.6.2;具体路径运行以后可以在终端看到
Windows: %APPDATA%\verdaccio\config.yaml
# 配置如下:
listen:
# - localhost:4873 # default value
# - http://localhost:4873 # same thing
- 你的IP地址:4873 # 这种才能使用外网、和其他电脑访问
npm adduser --registry http://localhost:4873
# 查看当前 npm 仓库源
npm get registry
# 设置 Verdaccio 为 npm 默认仓库;--- 不建议这么用
npm set registry http://localhost:4873
# 登录
npm login --registry http://localhost:4873
# 验证登录状态
npm whoami --registry http://localhost:4873
# 恢复默认的 npm 注册表
npm set registry https://registry.npmjs.org/
npm install my-package-name --registry http://localhost:4873
npm install -g pm2
# 6.1启动 Verdaccio
pm2 start `which verdaccio` --name "verdaccio"
# 6.2 设置开机自启
pm2 startup
pm2 save
# 6.3 Windows上pm2 startup报错处理,这个不一定生效;具体使用7. Windows 上使用.bat 开机自动执行
6.3.1 pm2 save
6.3.2 pm2 resurrect
6.3.3
# 使用.bat脚本
start_pm2.bat
# 内容如下:
@echo off
pm2 resurrect
# 当前用户:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
# 对于所有用户:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
@echo off
verdaccio
"C:\Users\xxx\Desktop\npm.bat" # xxx为用户名
@echo off
# 独立窗口运行,如果不希望子窗口弹出,可以添加 start /B
cd /d "D:\working\hyt-exam-cliten-html" && start "" npm run dev // 启动开发项目1
cd /d "D:\working\hyt-exam-systemhtml" && start /B "" npm run dev // 启动开发项目2
cd /d "D:\tool\fastgithub_win-x64" && start "" FastGithub.UI.exe // 启动安装程序FastGithub
pause
"C:\Users\xxx\Desktop\start.bat" # xxx为用户名
# 创建一个.bat文件,内容如下:
start snippingtool
具体错误如下:
verdaccio : 无法加载文件 C:\nvm4w\nodejs\verdaccio.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.micr
osoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 1
+ verdaccio
+ ~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [],PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Set-ExecutionPolicy RemoteSigned
# 格式:npm config set <包名>:registry <本地仓库地址>
npm config set lodash:registry http://localhost:4873
npm config get lodash:registry # 输出 http://localhost:4873,说明配置生效
npm install lodash # 此时 lodash 从本地仓库拉取,其他包仍用默认源
若本地仓库的包都带统一前缀(如 @company/*,scope 为 @company),可批量配置该 scope 下所有包指向本地仓库(适合团队内部包)。
# 格式:npm config set @<scope>:registry <本地仓库地址>
npm config set @company:registry http://localhost:4873
npm install @company/utils # 自动从本地仓库拉取
npm install lodash # 非 @company 包,仍用默认源
{
"name": "my-project",
"dependencies": {
"@company/utils": "^1.0.0",
"lodash": "^4.17.0"
},
"resolutions": {
// 格式:"包名": "npm:包名@版本" + "registry=<本地仓库地址>"
"@company/utils": "npm:@company/utils@^1.0.0 registry=http://localhost:4873",
"lodash": "npm:lodash@^4.17.0 registry=http://localhost:4873"
}
}
npm install --legacy-peer-deps
{
"name": "my-project",
"publishConfig": {
"@company:registry": "http://localhost:4873", // scope 批量配置
"lodash:registry": "http://localhost:4873" // 单个包配置
}
}
# 单个包指向本地仓库
lodash:registry=http://localhost:4873
# 某个 scope 下的所有包指向本地仓库
@company:registry=http://localhost:4873
# 可选:本地仓库需要认证时(如 Verdaccio 设了账号密码)
//localhost:4873/_authToken=你的认证令牌
# 单个包
npm config delete lodash:registry
# 某个 scope
npm config delete @company:registry
# 查看包的安装信息(包含 registry 地址)
npm ls <包名> --json | grep registry
# 示例:查看 @company/utils 的源
npm ls @company/utils --json | grep registry
# 输出 "registry": "http://localhost:4873" 即成功