Background:
In the company, in order to improve work efficiency, we will make some common JS libraries, or vUE components,react components. NPM install can be used directly next time, greatly improving work efficiency.
However, putting these things directly on nPMJs.com, for all to see, lacks confidentiality. So the question comes, can we build an NPM warehouse in the company LAN? The answer is yes, of course
Based on the NPM warehouse I built a few days ago, here is a brief introduction to you
Environment:
- CentsOS 6.5
- gcc
- g++
- nodejs
- make
- nrm
- Python 2.7
- sinopia
Precautions (Trampled pits)
- Make May not be installed on Linux by default, so you need to install it manually or it will fail to compile
- Python must be version 2.x, version 3.x does not support Sinopia
Official start (yum recommends using Ali Cloud mirror, NPM recommends Taobao mirror)
- Install the necessary packages
yum install -y make gcc gcc-c++ nodejs
npm i sinopia nrm -g
Copy the code
- Run Sinopia, which is the core of your local NPM repository
sinopia
Copy the code
At this point, open http://localhost:4873 and you’ll see a web page that comes with Sinopia, which shows you what packages are available locally and you can log in, but you haven’t registered yet
- NRM is a warehouse management tool, NRM The ls command to view all the NPM warehouse on the computer, we first new local [name] is the name of the warehouse, warehouse localNpm, for example, or use the company name. [url] is to build a warehouse that computer’s IP address and port, such as http://192.168.2.100:4873
nrm add [name] [url]
nrm use [name]
Copy the code
- Now you can add users
npm adduser
Copy the code
Running this sentence will prompt you to enter your username, password, and email address. Run it later if you need to log in
npm login
Copy the code
Log out and run
npm logout
Copy the code
- Publish package we first create a folder, pay attention to the name of the release package can not be someone else has published, such as vue, otherwise an error will be reported
npm init -y
npm publish
Copy the code
NPM init-y initializes the local repository, generating a package.json file that contains some basic information
NPM publish, as the name implies, is the packet to the local warehouse, not surprisingly, now more open http://192.168.2.100:4873 you will find a package, is that has just been released
- Use packages in the same way we normally use NPM
npm install [name] -S
Copy the code
- Json file, for example, 1.0.0 => 1.0.1, and then release the new version
npm publish
Copy the code
- Delete package, package published, if you do not want to use, how to delete, very simple, just need to
npm unpublish [name]
Copy the code
Note that the logged-in user must be the author of the publishing package