1, what is npm private service
The various packages we normally use for our front-end (web, nodejs), what with vue, react, react-router, zustand, etc., will all come from the/ This mirror source on the download, of course, our domestic development in order to download convenient, fast down, download packages will be specified when the domestic mirror source, such asTaobao mirror image. Mirroring services like these that are offered for network-wide use are public services.
Public service services all over the world the whole network compatriots, if it is the company's internal use of packages, containing some customization, privatization, not convenient to publish to the extranet components or packages, how should be dealt with?
common practice.
1, packaged into a component, the next time which project or development want, come over to copy the following
2. Commit to the company's intranet gitlab (intranet gitlab build), and then in the dependencies, use the gitlab address plus the branch name to use this package
3. Of course there are other odd kinky techniques
The above approaches have corresponding problems, such as the inability to maintain in one place, new features or bug fixes are difficult to synchronize to the various projects, there is no concept of versioning, and so on.
Wouldn't it be silky smooth to have a private service like the Taobao Mirror Service? Yes, the npm private service can meet the requirements of our privatized service.
2. What is verdaccio
There are many npm services out there, such as sinopia, cnpm, etc. But when you google npm private service, most of the results come up with verdaccio. But when you google npm private service, most of the results come up with verdaccio. Undoubtedly, this verdaccio is the most popular one. github address.vedaccio, official website address.official website, not much else to say, learn more about verdaccio, nothing more comprehensive than the official website and github.
3, why build npm private service
As to why build npm private service, the first point explains some of the background is also the reason, another, after the private service build, the company cicd jekins this kind of automation build work in pulling these packages, because they are going to the intranet, will go to the public network to pull faster than; npm private service build is also front-end automation link is a very important link; of course, this is also regarded as a technical kpi in the one.
4, how to build verdaccio
Come on, come on, go straight to the official website.
Verdaccio is a private and proxy registry. Before installing it, you need to ensure that the following conditions are met on your system environment.
Minimum requirements.
v16 or higher.
Your favorite Node package manager npm, pnpm, or yarn (classic and modern).
Use modern browsers to access the web interface, with support for Chrome, Firefox, Edge and IE11.
Installing cli
npm install -g verdaccio
activate (a plan)
pm2 start verdaccio
pm2 is a nodejs process management tool, here do not do embellish narrative, pm2 this method is more suitable for front-end students or nodejs students to use.
After the above two commands are executed, you will be able to access your private service.
This approach can be used locally as well as on liunx servers, without adding extra mental burden and extra learning costs.
5. Use after building
Publishing Components
The following 100.000.100.1 is the ip address of the server, blindly written, the actual use of the time to replace the server ip can be
registered user
npm adduser --registry http://100.000.100.1:4873
Enter your account number, password, and e-mail address (feel free to fill in any of these, but keep in mind that you'll need them for the next login).
registered user
npm login --registry http://100.000.100.1:4873
Enter account number, password and email address
npm publish Publishing components
npm publish --registry http://100.000.100.1:4873
Go here and you'll be able to see your components.
6. Common problem solving
Private theme customization, for example, I want to change the header, footer, favicon, etc. to the company's or my own. Please modify the web field in verdaccio's configuration file. Configuration file location: /root/.config/verdaccio/ .
vim /root/.config/verdaccio/
# Hosts and ports Verdaccio listens on
listen: 0.0.0.0:4873
# Location of the storage package
storage: . /storage
# Configure settings for the upstream mirror source
uplinks: .
. /storage # Configure upstream mirror source settings uplinks: .
url: /
# Configure package access and scope
packages.
'@scope/*'.
access: $all
publish: $authenticated
proxy: taobao
# Verdaccio's authentication settings
auth: $all publish: $authenticated proxy: taobao # Verdaccio's authentication settings
htpasswd.
file: . /htpasswd
# Configure Verdaccio middleware settings
middlewares.
audit: htpasswd: file: ./htpasswd
enabled: true
# Configure Verdaccio's logging settings
logs.
- { type: stdout, format: pretty, level: http }
- { type: file, path: , level: info }
# Configure Verdaccio's web interface settings
web: { type: stdout, format: pretty, level: http }
title: Verdaccio
logo: theme: default
theme: default
# Configure Verdaccio's security settings
security: api.
api.
jwt.
sign: jwt: jwt: jwt: jwt: jwt.
expiresIn: 7d
verify: maxAge: 7d
maxAge: 7d
web.
headers.
X-Content-Type-Options: 'nosniff'
X-Frame-Options: 'deny'
X-XSS-Protection: '1; mode=block'
After the modification, you need to restart verdaccio, in order for the configuration file to take effect.
pm2 restart verdaccio
The console reports 500 internal error when npm installs.
(sth. or sb) else
1, domain name configuration, do not ip access
2、Configure https certificate
3、Automatic release of components & update component version number
The above several problems, have been solved, at present, because of space reasons, time and other reasons, this article does not do a detailed expansion, will be in the next article to do a detailed explanation.
This content is not very suitable for students who do not have a little linux foundation or nodejs, related knowledge, please study separately, such as linux server purchase, linux server basic commands to use, pm2 installation and use. The most important thing to remember is that it's not just a matter of how you do it, but also how you do it.
8、Searching for friends who are using or want to use verdaccio
If you need or like to use verdaccio friends, welcome to add my WeChat (note verdaccio, or npm private service) to pull the group together to discuss the use of.
At present, this set of private service has been in the service of the company, the longer the use of time, the more problems, welcome to participate in the discussion, so that the private service is more stable and better to use!