在package.json中定义私有注册表

时间:2017-07-23 08:17:33

标签: node.js npm package.json npm-private-modules

我们有一个基于Sinopia

的私人npm存储库

我应该在package.json中定义哪些软件包将从Synopia而不是从全局npm存储库安装?

如果我从命令行安装它,我可以运行:npm install <package_name> --registry <http://<server:port>

P.S。试图谷歌并查看官方NPM文档,但没有找到任何结果。

2 个答案:

答案 0 :(得分:10)

我知道的方法之一是.npmrc 您也可以在项目中使用.npmrc

像这样设置配置

registry = http://10.197.142.28:8081/repository/npm-internal/
init.author.name = Himanshu sharma
init.author.email = rmail@email.com
init.author.url = http://blog.example.com
# an email is required to publish npm packages
email=youremail@email.com
always-auth=true
_auth=YWRtaW46YWRtaW4xMjM=

auth可以生成          用户名密码 echo -n&#39; admin:admin123&#39; | openssl base64

输出YWRtaW46YWRtaW4xMjM =

答案 1 :(得分:0)

sinopia的全部内容同时是私人registryproxy。您可以使用uplinks从一个注册表入口点安装所有软件包。如果本地存储无法解析依赖关系,Sinopia能够路由到任何注册表。默认情况下,他pointsnpmjs

因此,如果您将配置设置为

   # 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

您应该能够独立于每个依赖项的来源解析所有依赖项

btw:sinopia已不再维护。