.npmrc
文件用于配置 npm 的行为和设置。可以在项目根目录、用户目录(~/.npmrc
),甚至全局配置目录下(/etc/npmrc
)创建或编辑此文件来设置各种 npm 配置选项。
下面是一些常见的 .npmrc
配置选项及其用途:
-
设置注册表(registry):
registry=https://registry.npmjs.org/
-
配置代理:
proxy=http://proxy.company.com:8080 https-proxy=http://proxy.company.com:8080
-
设置缓存路径:
cache=/path/to/cache
-
配置认证 token:
//registry.npmjs.org/:_authToken=your-token-here
-
禁用包的引号:
save-exact=true
-
设置默认的包发布标签:
tag=beta
-
启用或禁用 strict-ssl:
strict-ssl=false
示例 .npmrc
文件
以下是一个示例 .npmrc
文件,展示了多种配置选项:
registry=https://registry.npmjs.org/
proxy=http://proxy.company.com:8080
https-proxy=http://proxy.company.com:8080
cache=/path/to/cache
//registry.npmjs.org/:_authToken=your-token-here
save-exact=true
tag=beta
strict-ssl=false
使用命令行配置
也可以通过命令行设置 .npmrc
文件中的配置,例如:
npm set registry https://registry.npmjs.org/
npm set proxy http://proxy.company.com:8080
npm set https-proxy http://proxy.company.com:8080
npm set cache /path/to/cache
npm set //registry.npmjs.org/:_authToken your-token-here
npm set save-exact true
npm set tag beta
npm set strict-ssl false
这些命令将会自动更新对应的 .npmrc
文件。
文件位置
- 项目级配置: 在项目的根目录下创建
.npmrc
文件。 - 用户级配置: 在用户的主目录下创建
.npmrc
文件(例如~/.npmrc
)。 - 全局配置: 在系统的全局配置目录下创建
npmrc
文件(例如/etc/npmrc
)。
检查配置
要查看当前的 npm 配置,可以使用以下命令:
npm config list
这会显示所有当前的配置,包括来自不同层级(全局、用户、项目)的配置。
前端工程师、程序员
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战