Is there any way to configure multiple registries in a single npmrc file

前端 未结 11 811
孤独总比滥情好
孤独总比滥情好 2020-12-02 06:06

Here is my problem. We have a private NPM registry which only works in VPN. I would like to have a fallback registry https://registry.npmjs.org so that when I am out of VPN

11条回答
  •  情深已故
    2020-12-02 06:30

    My approach was to make a slight command line variant that adds the registry switch.

    I created these files in the nodejs folder where the npm executable is found:

    npm-.cmd:

    @ECHO OFF
    npm --registry https://registry.npmjs.org %*
    

    npm-:

    #!/bin/sh
    "npm" --registry https://registry.npmjs.org "$@"
    

    Now, if I want to do an operation against the normal npm registry (while I am not connected to the VPN), I just type npm- where I would usually type npm.

    To test this command and see the registry for a package, use this example:

    npm- view lodash
    

    PS. I am in windows and have tested this in Bash, CMD, and Powershell. I also

提交回复
热议问题