搭建npm私库(超简朴)

缘由

我搭私库的缘由很简单,现在正在开辟一个组件库,提供给公司内部运用,我不想去注册npm,也不想守候npm的考核,只想要有个堆栈疾速测试宣布本身的npm包。

怎样搭

现在最轻易的计划就是verdaccio,搭建异常轻易,平常就几分钟就搞定了,须要的东西:

  • 装置nodejs和npm
  • 全局装置verdaccio
  • shh和pm2(非必需,假如你要布置到长途效劳器的话)

接下来细致引见搭建的步骤。

全局装置verdaccio

装置verdaccio之前,我默许人人都已装置了nodejs和npm环境,这个就不再赘述了。假如是当地搭建的话,直接进行下面的操纵就能够了。假如是在长途效劳器搭建,经由过程ssh衔接长途效劳器就行。

# 全局装置
npm install verdaccio - g

修正verdaccio设置

修正设置的目标就是让我们的私库能够经由过程公网的ip接见,起首检察npm全局装置包的地点位置:

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

设置状况以下

#
# 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接见

listen: 0.0.0.0:4873

然后输入:wq保留并退出vim形式,启动verdaccio效劳即可。我平常会经由过程pm2启动,缘由很简单,封闭doc窗口后,效劳不会停掉,并且能很好的治理我们启动的效劳。

运用pm2

常用命令

  • 装置:npm install pm2 -g
  • 启动:pm2 start verdaccio
  • 住手:pm2 stop verdaccio
  • 重启:pm2 restart verdaccio
  • 删除运用:pm2 delete verdaccio
  • 检察日记:pm2 logs verdaccio

我们来启动效劳,检察结果:

pm2 start verdaccio

《搭建npm私库(超简朴)》
至此,npm的私库搭建就完成了,图中是我最新宣布的一个基于vue的组件库,后续会对组件库的编写和宣布做引见,有兴致的朋侪关注以下。

    原文作者:干锅田鸡
    原文地址: https://segmentfault.com/a/1190000019301247
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞