windows下安装本地化npm包管理服务
csdn上的同步文章 windows下安装本地化npm包管理服务 详细实例过程_过客猫2022的博客-CSDN博客
安装依赖包
- 系统:windows 11,
- npm服务器的包是:verdaccio@5.21.1
- node:16.x
- npm install verdaccio@5.x -g
- 工作路径:d:\zdhsoft\verdaccio
配置文件
- 在目录d:\zdhsoft\verdaccio新建一个配置文件config.yaml
- 内容如下:
#
# This is the default config file. It allows all users to do anything,
# so don't use it on production systems.
#
# Look here for more config file examples:
# https://github.com/verdaccio/verdaccio/tree/master/conf
#
# path to a directory with all packages
storage: D:/zdhsoft/verdaccio/storage
# path to a directory with plugins to include
plugins: D:/zdhsoft/verdaccio/plugins
web:
title: zdhsoft NPM库
# comment out to disable gravatar support
# gravatar:
# by default packages are ordercer ascendant (asc|desc)
sort_packages: asc
# convert your UI to the dark side
# darkMode: true
# 自己随便配置一个logo和favicon
logo: D:/zdhsoft/verdaccio/logo-white.png
favicon: D:/zdhsoft/verdaccio/favicon.ico
# favicon: http://somedomain/favicon.ico | /path/favicon.ico
pkgManagers:
- npm
- yarn
# translate your registry, api i18n not available yet
i18n:
# list of the available translations https://github.com/verdaccio/ui/tree/master/i18n/translations
web: zh-CN
auth:
htpasswd:
file: D:/zdhsoft/verdaccio/htpasswd
# Maximum amount of users allowed to register, defaults to "+inf".
# You can set this to -1 to disable registration.
max_users: -1
max_body_size: 500mb
# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/
taobao:
url: https://registry.npmmirror.com/
packages:
'@zdh/*':
# scoped packages
access: $all
publish: $authenticated
unpublish: $authenticated
proxy: taobao npmjs
'**':
# allow all users (including non-authenticated users) to read and
# publish all packages
#
# you can specify usernames/groupnames (depending on your auth plugin)
# and three keywords: "$all", "$anonymous", "$authenticated"
access: $all
# allow all known users to publish/publish packages
# (anyone can register by default, remember?)
# publish: $authenticated
# unpublish: $authenticated
# if package is not available locally, proxy requests to 'npmjs' registry
proxy: taobao npmjs
# You can specify HTTP/1.1 server keep alive timeout in seconds for incoming connections.
# A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.
# WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enough.
server:
keepAliveTimeout: 60
listen: 0.0.0.0:4873
middlewares:
audit:
enabled: true
# log settings
logs: { type: stdout, format: pretty, level: http }
#experiments:
# # support for npm token command
# token: false
# # disable writing body size to logs, read more on ticket 1912
# bytesin_off: false
# # enable tarball URL redirect for hosting tarball with a different server, the tarball_url_redirect can be a template string
# tarball_url_redirect: 'https://mycdn.com/verdaccio/${packageName}/${filename}'
# # the tarball_url_redirect can be a function, takes packageName and filename and returns the url, when working with a js configuration file
# tarball_url_redirect(packageName, filename) {
# const signedUrl = // generate a signed url
# return signedUrl;
# }
# This affect the web and api (not developed yet)
#i18n:
#web: en-US
控制台下启动
- 新建一个v.bat,也可以直接在控制台下面输入下面命令
- 内容如下
verdaccio -c D:\zdhsoft\verdaccio\config.yaml
配置用户
- 在控制台下,进入目录d:\zdhsoft\verdaccio
>d:
>cd D:\zdhsoft\verdaccio
>npm install htpasswd-for-sinopia -g
>sinopia-adduser
- 按照提示输入用户名和密码 这个信息会存在当前的htpasswd的文件中
- 然后启动verdaccio,再进入在浏览器 http://localhost:4873/
- 就可以登录了,并可以通用这个用户发布你的定制npm包
- 如果不是你想要的用户,可以用编辑器编辑htpasswd,删除你不要用户就可以了
安装服务
- 这里使用的是工具是nssm 一个开源的工具 NSSM - the Non-Sucking Service Manager
- 下载地址:www.nssm.cc/release/nss…
- 解压后,就可以看到有32位或64位的nssm命令
- 然后在管理员的控制台下面:nssm install LocalNPMService
-
LocalNPMService 这个是你服务的名称,安装成功后,可以在windows带的服务管理看到这个服务名称 -
-
填写信息:
- path: node
- Startup directory: d:\zdhsoft\verdaccio
- Arguments: C:\Users\rex\AppData\Roaming\npm\node_modules\verdaccio\build\lib\cli.js -c D:\zdhsoft\verdaccio\config.yaml
-
然后点击install service就可以了(其它的设置,可以有兴趣研究一下)
-
最后在windows服务管理,就可以看到这个服务了
-
-
最后
- npm config set registry=http://localhost:4873 就可以用了