范围
范围包
描述
所有 npm 包都有一个名称。一些包名也有范围。范围遵循包名称的通常规则(URL 安全字符,没有前导点或下划线)。在包名中使用时,作用域前面有一个 @
符号,后面是一个斜杠,例如
@somescope/somepackagename
范围是一种将相关包组合在一起的方式,也影响 npm 处理包的方式的一些事情。
每个 npm 用户/组织都有自己的范围,只有你可以在你的范围内添加包。这意味着您不必担心有人抢先您的包名称。因此,这也是向组织发出官方包信号的好方法。
范围包可以从 npm@2
开始发布和安装,并且受主 npm 注册表支持。无范围包可以依赖于范围包,反之亦然。npm 客户端向后兼容无范围注册表,因此它可以同时用于作用域和无范围注册表。
安装范围包
F7KUvMGgQcR62G5DCMe38nGivnq+W7I61zaOaNqEOzELZuXehdkcXSGN8PDXy9Ai4S/oc80/LZNMRn9x2QU4F39pZy73t2yyezal9K9/f3NJtTMUCc23+uTsuRtdYKqpeRbxzFA6u6NJ6POs+pMX70BZNF9td5wmjNNCTt/JWWCxu6pdW4B15+0PHFvuWgKD1HMdcjl5edK5s0TN5yJeTJJ9DxcX9vTlYB3YNmj10BP/igYQyhoNHRrLIKflIqnh4eAiFgsSLgs4i2UQNHg2ZuNvp+Yyj0FmTlSv+w+81Jn3PYSgBd1wtznuMPXHGqqR/huO+DwX1MGzw0qwDfydD3b+7MLTk3IMi9eEbhF9vs14k6N/0EpZO5wnrGRPCNDUjCNXoU6sH8hS6JedsJ4G0HXNUS55gUAh5iyBuzL7pbb79v/fYkr/XgxHumpDGTZZaG8z8xTCVbAySLG3/LLZgHFvFaI1k9csUfr7x+YlmyQ=
RZFak76moRdpvtXCCiIFpBlmhyjhHltHgIjsrD7DrfAyqb8H2ggrgN8RGft7tC37DAJ6ox/786G7F7YXFBpiDPUmqFxOFJmnaaRbLxixQzhgaAz0f6lL20v6JIPSIEVRI1ybjUkXUo9rnETJyryJKKBneOJFwtQP0u2TI5oQ0Ts=
npm install @myorg/mypackage
IlQy6hbSgkIaX7j+kyZe7OMBDzYvdUMtjZVbikqxQzwrKslFys5Vb37hRrcyE/T/
"dependencies": {
"@myorg/mypackage": "^1.3.0"
}
OiDR+NlxGmdmHfdP1hROeLZEURemmade68Q4fh+54aJ0XW22VQgbbvsgiRpyROytppUpbDgXtNZiCO7R4Iqaa7K05UHCI18tZhKox1cYR1df3s4gdRUieso7GRqAwhAA20r2Awt0pju02tVRIE/0Y8i3zFgzDT6rMDKDJzkeFjAWzpWG+qI7JvQKe+F22xHhdXc1g6kYOfE5zk1SbDHoB4Inl2Ld0zLJqgFLyCK6Bk2rYdQAvCBaEMnM/xrPeLAR
需要范围包
6NMxUyKy9GykkqsJisdNX3IJE3lhUD2PJ8e8HJl8gvzauW/v4hfBaLR3uvl92WZvFF4XjOS9XVam2j8PU8VbcO1DE2DqIkvyDy+Noz//mImWRdpIcVVL3ddlIRmte7zD6FxUMMNABwHKWryK7qo39P2/0Msc3KSSb7VkwGLrUr4=
require('@myorg/mypackage')
pYGX3vGGfppnVmTM659qZoH5X5fhYSEKHQTjEiN52qvrUOnILtfXPl6C7rnQfgCSDMvXZ5ItrYi4pXNI+A6c3f72rVMbwspde1rVQ/5VF8NWbfrLawfbsjak+8n2bi1nfnsd9yAO+BOD7j7//dOy/P1iUA2ptK35yx5Ny4h+kwpU5UrDSFEHoNrhRjarF+8IUrUnp3Wc4INfVL/uQkAjcQ==
发布范围包
RKlRG0Xky0s8014BNKzX7dUmNlSEcFzKuNLh+gFTOGRARcvniRSMWeEzvLxULJPUiZV8eSyUcIVMEO1bfT70xV/iD8cfjM/pHLQy6n+e3EKDpQE1KcyeJi9e4jf7C7aMfj7G2q9THyK9okLzUREHgtKPcDsZ8hNngM3P807ZRmcT+aL8oO0HSAk7wXO7zOdg
OGwFBvIIxT9COCr1+Z30tudmy9FfML5Egz0D2vuytLb+JpDlB/0okymLh43MdbeIO805ksd0DO5JfgrKKpE8UAxMc2Zf2pYBKwPhRR/LEG+1JONd9AH+HfaKCz8g7RMtNVwpw0O6LUBsqAwODrlzLQ==
YNtp2guH48zgUVZdAkp5yKekA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qWU9TOJYXUZQv3g7JLSQu3DYmLznGLkam+mBaB3s8eL6Q/Q5ND2lr/ilHVsATZSNsFxa/OYIhSrPyW75ojbn6u+63yN9FEgV+QESefwoawQsa+EF4kVsJEddqe1lCVBT1ZJmKa6dDSPL30oW3eYz6Nc02Da6Zr+FJG7gQsC+CMWSpaKoRV5fFX0olVCl2noE5GZkJCfePl3k/NmJoMvsMdpXPg==
将私有范围包发布到 npm 注册表
J7Nhh2qiLM4GYJ9yLuVH9gO+7aMj7iR3MwGGlCEX/vc5uL0RR2yaQkivbesfL3BcfwLtn99Kynk1SO4T7sSaH7I1xbgcdSOd0w+Kug2zRVs7KmI9nYRysXiyr7SjFJuR+Qg2PHKpLHmIaFjzx9GAlqEDnm1HriAHiMdZqxyX+Wka9fhnmTUeApkZCtjXOVKD
9GoVm0uCOJweluTNsbNP91mVu6ReP5oCyUk/kwBN1otC2mT9oRRfvpMCHVj7C32BNtsjMbTLPOQyNNXq1Zbu44AX/JJFcEkGmB8vM6VBFC/bXwmaqa9S0QF91t296kAk3tcO51vxxIPorH6L7eAtEAO8ZXeCtFN651qgvf+utAJXZK1W/UPSb9oH7RirTPcfLJJxd8XJMwF5xLTTWqncW92sYCC3uKyXuV6//jjD8XiOS3HZzoA8/RgexlTcKC0xtrwPcA8EmUHc4FfdTzWHT9JotICTh3T/LTM4CzzyPEIYLOn9TB4vuHHHBzutD919DjKElW5GxZtpq/TQ6HxkrJPgYhsmTjhxgsJD6kqZr0uARXhwX9TpsXVQ9E2dMLUI
将范围与注册表关联
+StxvBKqjw5eewjxmszAKsTW55uscH5hYlitCmGt3ExXOehofRGhj70JrOiERQppt2Hh18wJJAB+WrGOldj0OE1VAHzSisqblT3AVJ/7rfbBdrMTAzjsQIyyV3XsgNRmE6W73S8ElANSfmMtlp/7tq0MB9673B8coI1zUUqgV04lCjKFpboBJzZjg4+zmsFS/2h4hinCLDLTmOQyHMoKERPyYXnV519jMBZvAgozAeG/0GLGgm4RzqQxyyKaBbqxEsz05eYTdfolX8ZKINRzgMWAEOGm2FpRKQsVnlg8iDMX2CJD5GU1cqmc0FS4+AGo/iWir3y5kSS9Y1HV4bhalo2DzD/xb1k+zyGR73nDInFKziwN5KE4Nbl79tujCkE8tKb+0MIfPccqhEBD4D5/tA==
a16XyUF96SFZDBkX7fe6aVP61pg87zZ/Zgeo3UZgQkbXZeg9NyyJRMgH174yHxnDUVYbAZG1yUtcQkjUE531zg==
npm login --registry=http://reg.example.com --scope=@myco
ZPafpPZ9/l7jWzah9u4KZu5W+40PBsmN2oT0QX05vOACM8QE9kQNNEhpgani5RVM+0ueX8VH34ZJ2tiRlsl1pAJTdmgP9izJLYmS1i6gs4sk1RGgnmANZ/6oE+K/WHy3nhAOmVJfhvOv20KnY+OOMm4bZJHgGLyTCcNdxx/6oNLkrifXbZrudYRYJNuUPDvM
De7CIboB36NGSbVkR0iJPrjB1fV8dMDUHfvarJVKs4xhJglCyriEZk7O4cpMGAFEjQ5w9Y7IDnRL7w3hbfjXXqolj5xsGpYmDPDaXIWGJR0=
npm config set @myco:registry http://reg.example.com
mlW4dh0xeHE8a+/1Hn7R/ytM04PMDd2cLHHsh3b69rztNLnT9Jb1YW7azgUi5iCvyMkr6gpMXVHWVK+2P7fbOYn/XCWfaonpiDcQ0cdzeEcG2KIfvC+16M/EzUF6EhjikvKyUPvzcczMK2MTi3Gjs++JB1+fpdnG0ng5pR8uGw7dhHzeVm7dLp2ZssMtRcaNvwLmsM4rz5JGA/jkiXg4YhszL9tkWqxwa85xu8MjXf/BmFJDkMUO+HIcn9LNi1mAgoa89gonOmBjlrf+tGjChu3bXRzhm6OKhiZjn6g1V1o=