preface

When we run the front-end projects, often at the time of dependency resolution will add a parameter NPM install – source of registry=https://registry.npm.taobao.org will be designated as the source of taobao, in order to speed up, in fact this can indeed make faster, But in the long run, if you want to really fast and agile development deployment, build the private server inside the enterprise, it will make the speed up to a higher level.

To build the NPM private server, we still use the nexus3.

Like other private servers, NPM private servers come in three types:

  • hosted: Local storage, that is, the same as the official Docker warehouse to provide local private server function
  • proxy: Provides a type of proxy for other repositories, such as a Docker central repository
  • group: group type that essentially combines multiple warehouses into one address

So let’s create them one by one.

1. Create bloB storage

Create a separate storage space for the NPM private server.

2. Create an NPM of the Hosted type

  • Name: Define a name local-npm
  • Storage: Blob Store, we drop down to select the dedicated Blob: NPM-hub that we created earlier.
  • Hosted: Development environment where we run repeated publishing, therefore Delpoyment Policy we select Allow Redeploy. This is important!

3. Create a proxy NPM repository

  • Name: proxy-npm
  • Proxy: Remote Storage: Address of Remote Storageregistry.npmjs.org
  • Storage: NPM – the hub.

Everything else is default.

The following figure shows the overall configuration:

4. Create a group NPM repository

  • Name: group – NPM
  • Storage: Select a dedicated BLOB storage NPM-hub.
  • groupAdd the two repositories that are optional on the left to members on the right.

The following figure shows the overall configuration:

Once these configurations are complete, you can use them.

5. Verify use

Gets the default warehouse address

npm config get registry https://registry.npmjs.org/
Copy the code

Configure it as a private server address.

View it in the following screenshot (actually, it is the external address of the created group).

Open your own front-end project and run the following command to configure it:

NPM config set registry http://192.168.75.11:8081/repository/group-npm/ NPM config get registry http://192.168.75.11:8081/repository/group-npm/Copy the code

To start the installation, take a look at the contents of the group:

You can see it’s still empty.

npm install
Copy the code

After the installation, refresh the warehouse, as shown below:

There’s something in there.

Pay attention to the point

NPM install error:

Solution: 1. Check Realms Settings for NPM Nexus, put NPM Bearer Token Reaim into Active and save

2. Check whether Anonymous is open on Nexus Repository Manager

2. Log in to NPM

npm login
Copy the code