我搭私库的缘由很简单,目前正在开发一个组件库,提供给公司内部使用,我不想去注册npm,也不想等待npm的审核,只想要有个仓库快速测试发布本身的npm包。vue
目前最方便的方案就是verdaccio,搭建很是方便,通常就几分钟就搞定了,须要的工具:node
接下来详细介绍搭建的步骤。git
安装verdaccio以前,我默认你们都已经安装了nodejs和npm环境,这个就再也不赘述了。若是是本地搭建的话,直接进行下面的操做就能够了。若是是在远程服务器搭建,经过ssh链接远程服务器就行。github
# 全局安装 npm install verdaccio - g
修改配置的目的就是让咱们的私库能够经过公网的ip访问,首先查看npm全局安装包的所在位置:web
npm root -g /usr/local/Cellar/node/8.4.0/lib/node_modules
其中/usr/local/Cellar/node/8.4.0/lib/node_modules即是咱们npm包全局安装的地址。按如下命名查找配置文件所在的位置
而后npm
vim default.yaml
配置状况以下vim
# # This is the default config file. It allows all users to do anything, # so don't use it on production systems. # # Look here for more config file examples: # https://github.com/verdaccio/verdaccio/tree/master/conf # # path to a directory with all packages storage: ./storage # path to a directory with plugins to include plugins: ./plugins web: # WebUI is enabled as default, if you want disable it, just uncomment this line #enable: false title: Verdaccio auth: htpasswd: file: ./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: https://registry.npmjs.org/ packages: '@*/*': # scoped packages access: $all publish: $authenticated proxy: npmjs '**': # allow all users (including non-authenticated users) to read and # publish all packages # # you can specify usernames/groupnames (depending on your auth plugin) # and three keywords: "$all", "$anonymous", "$authenticated" access: $all # allow all known users to publish packages # (anyone can register by default, remember?) publish: $authenticated # if package is not available locally, proxy requests to 'npmjs' registry proxy: npmjs # You can specify HTTP/1.1 server keep alive timeout in seconds for incomming connections. # A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout. # WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enought. server: keepAliveTimeout: 60 # To use `npm audit` uncomment the following section middlewares: audit: enabled: true # log settings logs: - {type: stdout, format: pretty, level: http} #- {type: file, path: verdaccio.log, level: info} # listen listen: 0.0.0.0:4873
最后一行为新增的配置, 用于支持外网ip访问bash
listen: 0.0.0.0:4873
而后输入:wq保存并退出vim模式,启动verdaccio服务便可。我通常会经过pm2启动,缘由很简单,关闭doc窗口后,服务不会停掉,而且能很好的管理咱们启动的服务。服务器
经常使用命令ssh
咱们来启动服务,查看效果:
pm2 start verdaccio
至此,npm的私库搭建就完成了,图中是我最新发布的一个基于vue的组件库,后续会对组件库的编写和发布作介绍,有兴趣的朋友关注如下。