Company internal front-end components or library sharing, building a NPM private library is very convenient, now large and medium-sized companies also have their own NPM private library, this article, and we work together to build a NPM private library, learn ~
You need a server, the configuration of NPM private library is not high, 1 core 2 GB, but we will map the uploaded package to the server local, recommend a large hard disk.
Install Docker
The Linux server uses curl to download shell scripts for quick installation
curl -fsSL get.docker.com -o get-docker.sh
Copy the code
Once the download is complete, you can view it using the ls command. If it already exists, run the sh command to execute the script
sh get-docker.sh
Copy the code
Notice If you are not the root user, run sudo su to obtain the super administrator permission.
After the installation is complete, start Docker Server
systemctl start docker
Copy the code
Using the docker version command, you can see that the Client and Server are successfully started.
2. Install Verdaccio based on Docker
1. Prepare the configuration file
mkdir /home/verdaccio
cd /home/verdaccio
mkdir conf && mkdir storage && mkdir plugins
cd conf
touch htpasswd
vi config.yaml
Copy the code
Execute each of the above commands in sequence, and then write the configuration in config.yaml
Storage:... /storage # plugins:... / plugins web: # site Title Title: Verdaccio # # disable them them: false # sort by asc | desc # sort_packages: Asc # whether to enable the diablo pattern # darkMode: true # # logo address logo: http://somedomain/somelogo.png # # favicon favicon address: # http://somedomain/favicon.ico | / path/favicon. Ico i18n translation configuration # i18n: # # available list to see: https://github.com/verdaccio/ui/tree/master/i18n/translations web: en - US auth: htpasswd: file: Uplinks: NPMJS: url: uplinks: NPMJS: url: uplinks: NPMJS: url: https://registry.npmjs.org/ packages: # scope package '@ * / *' : # to allow everyone access to access: $# all registered users can access the publish: Unpublish: $authenticated Proxy: NPMJS '**': You can specify the user name/group name (depending on what authorization plugin you use, the default authorization plugin is the built-in htpasswd). "$all", "$anonymous", "$authenticated" # $all # $anonymous indicates access for unregistered users; # $authenticated means only registered users have access to access: $all # allows all registered users to publish/revoke published packages # (note: by default anyone can register) $authenticated unpublish: $authenticated # If the private package service is not available locally, the proxy requests to 'NPMJS' proxy: NPMJS # You can specify the HTTP /1.1 server stay active timeout (in seconds) for incoming connections. A # value of 0 causes the HTTP server to behave similar to the pre-8.0.0 version of Node.js, which did not hold active timeouts. Server: keepAliveTimeout: 60 # Middleware Middlewares: Audit: enabled: true Stdout, format: pretty, level: HTTP} # open remote access, allow all IP listen: -0.0.0.0:4873Copy the code
2. One-click install and run Verdaccio
V_PATH=/home/verdaccio; docker run -d -it --name verdaccio \
-p 4873:4873 \
-v $V_PATH/conf:/verdaccio/conf \
-v $V_PATH/storage:/verdaccio/storage \
-v $V_PATH/plugins:/verdaccio/plugins \
verdaccio/verdaccio
Copy the code
The NPM private library can be accessed through http://server IP :4873.
3. Grant permission to the software package directory and user record file directory
This step is mandatory; otherwise, new users and software packages cannot be uploaded.
chown 10001:65533 /home/verdaccio/conf/htpasswd
chown 10001:65533 /home/verdaccio/storage
chown 10001:65533 /home/verdaccio/plugins
Copy the code
Manage NPM source, registered users and release packages
1. Replace the NPM source with the private library source
$NPM config set registry http://127.0.0.1:4873Copy the code
Replace the default NPM source directly with our private library, but it is not easy to manage multiple sources. Therefore, it is recommended to use NRM to manage our NPM source.
2. NRM manages NPM sources
NRM $NPM install -g NRM # Add private library $NRM add verdaccio http://{server IP}:4873 # View existing NPM source $NRM ls * NPM -------- https://registry.npmjs.org/ yarn ------- https://registry.yarnpkg.com/ cnpm ------- http://r.cnpmjs.org/ taobao ----- https://registry.npm.taobao.org/ nj --------- https://registry.nodejitsu.com/ npmMirror -- https://skimdb.npmjs.com/registry/ edunpm verdaccio -- -- -- -- -- http://registry.enpmjs.org/ -- http:// {server IP} : $# 4873 / set NPM sources nrm use verdaccioCopy the code
3. Register private library users
$NPM adduserCopy the code
4. Log in to the private library user
$NPM who am ICopy the code
5. Distribute packages in private libraries
$NPM publishCopy the code
Here, all the installation, user registration, package release process has been completed, if you have any questions can private chat with me, or leave a message in the comment section.
Finally, I recommend other articles related to front-end engineering
Based on Docker (Gitlab, Gitlab Runner), set up a set of automated CI and CD processes to complete the process from code submission to automatic packaging and compilation to automatic deployment and operation
The front end builds its own scaffolding (CLI) to realize the internal front end engineering
Git submission normalization with commintLint + husky