资讯专栏INFORMATION COLUMN

搭建npm私库(超简单)

xbynet / 2027人阅读

摘要:原因我搭私库的原因很简单,目前正在开发一个组件库,提供给公司内部使用,我不想去注册,也不想等待的审核,只想要有个仓库快速测试发布自己的包。我一般会通过启动,原因很简单,关闭窗口后,服务不会停掉,并且能很好的管理我们启动的服务。

原因

我搭私库的原因很简单,目前正在开发一个组件库,提供给公司内部使用,我不想去注册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包全局安装的地址。按以下命名查找配置文件所在的位置

然后

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的私库搭建就完成了,图中是我最新发布的一个基于vue的组件库,后续会对组件库的编写和发布做介绍,有兴趣的朋友关注以下。

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/109864.html

相关文章

  • 搭建npm私库简单

    摘要:原因我搭私库的原因很简单,目前正在开发一个组件库,提供给公司内部使用,我不想去注册,也不想等待的审核,只想要有个仓库快速测试发布自己的包。我一般会通过启动,原因很简单,关闭窗口后,服务不会停掉,并且能很好的管理我们启动的服务。 原因 我搭私库的原因很简单,目前正在开发一个组件库,提供给公司内部使用,我不想去注册npm,也不想等待npm的审核,只想要有个仓库快速测试发布自己的npm包。 ...

    Dongjie_Liu 评论0 收藏0
  • 2018年第12周-yum私库搭建

    摘要:此实验过程仅在上实践过先顶一下角色,假设我有三台服务器,,。除了库,我们还可以将库,库等,私有化。 此实验过程仅在centos上实践过 先顶一下角色,假设我有三台服务器A,B,C。 服务器A是centos6.5版本,目标:我想把它当做yum私库服务器B是centos7.2版本,目标:yum安装程序包时,不从internet上获取安装包信息,而是从服务器A获取安装包信息来安装服务器C是...

    lk20150415 评论0 收藏0
  • 舒适的前端开发环境是怎样一种体验?

    摘要:那我们有没有办法不刷新页面又能看到代码的更新呢其实很简单,因为已经内置了这样的功能,我们只要配置下的注意到上面的代码,我们增加了,让开发环境有了热更新的能力。 作者:Nicolas (沪江Web前端)本文为原创文章,转载请注明作者及出处 本文的 webpack 代码示例根据 webpack 2.7.0 编写,并在 Mac 上正常运行。 去年一篇《在 2016 年学 JavaScript...

    weapon 评论0 收藏0
  • 详细动手搭建一个Vuepress站点及开启PWA与自动部署

    摘要:五一之前就想写一篇关于的文章结果朋友结婚就不了了之了。记得最后一定要看注意事项更新仓库介绍官网类似一个极简的静态网站生成器用来写技术文档不能在爽。当然搭建成博客也不成问题。构建与自动部署用的或者的都可以也可以搭建在自己的服务器上。 五一之前就想写一篇关于Vuepress的文章,结果朋友结婚就不了了之了。记得最后一定要看注意事项! 更新:coding仓库:https://git.dev...

    zhoutk 评论0 收藏0
  • 【HEXO】从零搭建HEXO博客 修改默认主题/参数/favicon 替换个人主页

    摘要:下面我以主题举例,覆盖默认主题。其他元素使用相同的方法都可以修改。像这种超链接跳转的修改,在文件中找到直接把属性的值改变即可。 准备:搭建环境 大致分为以下两步: 安装Node.js 安装git 配置Node.js环境 下载Node.js安装 Windows Installer 32-bithttps://nodejs.org/dist/v4.2.3/node-v4.2.3-x...

    My_Oh_My 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<