When you want share a javascript package written by yourself among your different projects, you may not want to publish the package to the public npm repository or its paid private repository.
So you can use verdaccio to build a local repository.
Setup
npm install -g verdaccio
, you may need add sudo
if there are no permission.
Run
run verdaccio
in the bash.
It will show the url of the verdaccio server, and the default config. These two infomation is required at later.
warn --- config file - ~/.config/verdaccio/config.yaml
warn --- Plugin successfully loaded: verdaccio-htpasswd
warn --- Plugin successfully loaded: verdaccio-audit
warn --- http address - http://localhost:4873/ - verdaccio/4.0.4
As we see, the default server url is http://localhost:4873/
, the default config path is ~/.config/verdaccio/config.yaml
Steps to Enable Anonymous Pusblish
Edit the config.yaml
packages:
'**':
access: $anonymous
publish: $anonymous
proxy: npmjs
Restart the verdaccio server.
Resolve the problem of anonymous access still need token
According to this issue, we still need a fake token.
Create a .npmrc file under the project you are going to publish.
//localhost:4873/:_authToken="fooBar"
As you know, the localhost:4873
is verdaccio
server url.
Publish Package to Local
npm --registry http://localhost:4873 publish
Note the --registry
option set the target server to publish - here is the local verdaccio server.
Download the Package from the Local Repository
npm install --registry http://localhost:4873