Forwarding address blog.csdn.net/helloxiaoli…

How to set up a private NPM repository? Mainstream private NPM warehouse construction schemes in the industry are as follows:

1. Pay to purchase 2. Use Git + SSH to directly reference GitHub project address 3. Use Verdaccio 4.

The second type, which cannot be updated is NPM update, cannot use semver (semantic version specification).

That leaves only the third and fourth better options.

Verdaccio is a fork of the Sinopia open source framework, but since Sinopia was no longer maintained two years ago, since sinopia was all searched for online, I actually used it for a while and cried myself to death… . And because no one to maintain, all the bugs, what to look at the source code to solve it, so decisively abandoned the pit, found the Verdaccio

Use NPM global installation

NPM install -g Verdaccio Run After the installation is complete, run the verdaccio command

At this time, we open the browser and enter http://localhost:4873/ to open. If you are not deployed on host, change the following configuration to 0.0.0.0

The following yamL is the default configuration file, port 4873 represents the default port, now we can modify the default configuration file to suit our needs.

Full configuration of Verdaccio

The default configuration is shown in the following figure

The # sign is followed by a comment

The cache directory for all packages

storage: ./storage

Plug-in directory

plugins: ./plugins

Enable web services to access the web through the Web:

WebUI is enabled as default, if you want disable it, just uncomment this line

#enable: false title: Verdaccio # verify information auth: htpasswd: ./htpasswd # Maximum amount of users allowed to register, defaults to “+inf”. # You can set this to -1 to disable registration. #max_users: 1000

a list of other known repositories we can talk to

Uplinks: NPMJS: url: registry.npmjs.org/

packages: ‘@/‘: # scoped packages access:
a l l p u b l i s h : all publish:
authenticated

# agency said there was no warehouse will go inside the NPMJS find, # NPMJS pointing to https://registry.npmjs.org/ again, is the above uplinks proxy configuration: NPMJSCopy the code

‘* *’ : # 3 kinds of identity, all the people, the anonymous user, authentication (landing) user # “all”, “all”, “all”, “anonymous”, “$authenticated”

Publish: $authenticated # If the package does not exist, issue a request to the upstream service of the proxy proxy: NPMJSCopy the code

To use npm audit uncomment the following section

middlewares: audit: enabled: true

Listen to the port, IP address, key, do not configure this, only this function access

Listen: 0.0.0.0:4873

log settings

logs:

  • {type: stdout, format: pretty, level: http}

#- {type: file, path: verdaccio.log, level: info} How to use # current NPM service to point to local

npm set registry http://localhost:4873

Registered users

NPM adduser — registry http://localhost:4873 Enter userName and password,email as prompted

After entering, the registration is complete.

Check whether the current user is a registered user.

npm who am i

The last step is to create a folder and create a private package in the standard format of NPM Publish

Publish a package

npm publish

After successfully publishing a private package, we refresh to see that the package has appeared.

NPM install [package name] For example, if you want to install a vue,webpack, etc., if you can’t find it, it will be downloaded by the npm.js official website and cached in the./storage folder for you. Download it again, and you’ll be able to experience flying speed, especially when used by a small team.

Of course, if you still don’t like NPM and want to use CNPM, you can change the configuration

uplinks: npmjs: url: registry.npmjs.org/

Uplinks proxy: NPMJS for uplinks packages: ‘@/’: #

NPM —- registry.npmjs.org/ CNPM — r.cnpmjs.org/ taobao – registry.npm.taobao.org/ nj —– registry.nodejitsu.com/ rednpm – registry.mirror.cqupt.edu.cn/ npmMirror skimdb.npmjs.com/registry/ edunpm – Registry.enpmjs.org/ I used NRM, a repository manager, to simplify the following command: NPM set registry [url]