Define private registry in package.json

有些话、适合烂在心里 提交于 2019-12-05 18:30:21

问题


We have a private npm repository based on Sinopia

What should I define in package.json that some packages will be installed from Synopia rather then from global npm repository?

If I install it from command line I can run: npm install <package_name> --registry <http://<server:port>

P.S. tried to google and looked in official NPM documentation but have found nothing.


回答1:


One of the method i know that is by .npmrc You can also use .npmrc also inside the project

set configuration like this

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 can be generate by username:password echo -n 'admin:admin123' | openssl base64

output YWRtaW46YWRtaW4xMjM=




回答2:


The whole point of sinopia is a private registry and a proxy at the same time. You can use uplinks install all your packages from one registry entry point. Sinopia is able to route to any registry if the local storage is not able to resolve the dependency. By default, he points to npmjs .

So, if you set your configuration like

   # 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 should be able to resolve all your dependencies independently of the source of each of them

btw: sinopia has no longer maintained.



来源:https://stackoverflow.com/questions/45262977/define-private-registry-in-package-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!