我的公司有专用作用域npm
模块,即以@mycompanyscope/mymodule
开头的模块。通过默认设置在故宫所有范围的模块都是私人所以你必须首先登录之前发布如何在Microsoft Azure网站上安装npm作用域模块
npm login
Username:myusername
Password:**********
npm publish
作用域模块必须具备的使用性能name
与在package.json
一个范围:
{
"name": "@mycompanyscope/mymodule"
}
和private
关键必须删除。
只要你登录你在$HOME
文件夹获取在.npmrc
文件token
,就是喜欢
//registry.npmjs.org/:_authToken=00000000-0000-0000-0000-000000000000
scope=mycompanyscope
此时一切都正确设置,以publish
和install
在这台机器。如果您授予其他用户的访问权限,他们可以在他们的机器上执行npm login
并从中获取令牌。
问题出现在服务器端,具体取决于您的服务器。在Heroku上,它应该像解释here一样工作。
我的服务器环境是Azure网站。根据一些文档,您应该在部署阶段将您的.npmrc
文件上传到Azure,如果我有办法为该计算机获取令牌,那么这将非常棒。 如果我尝试登录到Kudu PowerShell
,事实是,我只是无法登录,登录过程挂起,在一些点:
Kudu Remote Execution Console
Type 'exit' then hit 'enter' to get a new powershell process.
Type 'cls' to clear the console
PS D:\home> npm login
Username: mycompany
Password: *********
Email: (this IS public) [email protected]
,使我无法生成从本机的任何标记。那么如何在这里授予访问权限以让npm install
正确运行专用范围模块?
[更新] 多亏了答案下面我就能够部署NPM范围的模块(@ mycompanyscope/Mymodule中)到Azure网站,创建.npmrc
文件在项目的根文件夹(其中package.json
是)然后写在那里的npm login
后获得的令牌,并添加registry
到npmjs.org
注册表:
//registry.npmjs.org/:_authToken=00000000-0000-0000-0000-000000000000
scope=mycompanyscope
@mycompanyscope:registry=https://registry.npmjs.org/
感谢您的建议。您提到的解决方案是使用'myget'来托管'npm私人注册表',以便您可以将它添加到'.npmrc'文件中,例如'npm install --save --registry https://www.myget.org/ F/demo-site/npm /'但我使用的是'npmjs.com'专用模块,并且我没有发现任何为我的'.npmrc'添加注册表的例子。 – loretoparisi
与之相同,当您运行命令'npm login'时,默认的注册表url是'registry.npmjs.org'。并根据https://www.npmjs上的描述。com/settings/tokens,你可以手动创建'.npmrc'设置auth令牌在这个页面中,让你的Azure Web Apps环境下载你的私有模块。 –
我确认这是解决方案。谢谢。我已经更新了这个问题。 – loretoparisi