当前位置:网站首页>实习打怪之路:npm/cnpm i -D和-s及-g以及–save 的使用区别【cnpm与npm的区别】
实习打怪之路:npm/cnpm i -D和-s及-g以及–save 的使用区别【cnpm与npm的区别】
2022-07-20 01:19:00 【The..Fuir】
目录
npm i -D和-s及-g以及–save 的使用区别
npm 相信大家都很熟悉了, 我们在项目中必须会用到的,但是每次用的时候就直接按照文档操作了, 也没有搞清楚-D, -s, -g, –save 的区别。正好借着这个文章整理分享一下吧。
npm是Node官方提供的包管理工具,他已经成了Node包的标准发布平台,用于Node包的发布、传播、依赖控制。npm提供了命令行工具,使你可以方便地下载、安装、升级、删除包,也可以让你作为开发者发布并维护包。
npm i module_name -S = > npm install module_name --save 写入到 dependencies 对象 npm i module_name -D => npm install module_name --save-dev 写入到 devDependencies 对象 npm i module_name -g 全局安装
i => install == 安装 -S => save == 保存 -D =>devDependencies => 写入devDependencies,发布到生产环境 -g =>global => 全局安装
在 package.json 文件里面提现出来的区别就是,使用 –save-dev 安装的 插件,被写入到 devDependencies 对象里面去,而使用 –save 安装的插件,责被写入到dependencies 对象里面去。
devDependencies 里面的插件只用于开发环境,不用于生产环境,而 dependencies 是需要发布到生产环境的。
npm和cnpm的区别?
(1)两者之间只是node中包管理器不同
(2)npm是node官方的包管理器,cnpm是中国版的npm,是淘宝定制的cnpm(gzip压缩支持)命令行工具代替默认的npm
(3)如果因为网络原因无法使用npm下载,cnpm就排上用场了
cnpm的下载
npm install -g cnpm -registry=https://registry.npm.taobao.org
很多人觉得npm不够快,所以使用cnpm
查看cnpm是否安装成功
cnpm -v
npm介绍
npm(node package manager)nodejs的包管理器,用于node插件管理(包括安装、卸载、管理依赖等)
-g 全局安装
--save 将保存配置信息至package.json
-dev:保存至package.json的devDependencies节点,不指定-dev将保存至dependencies节点
为什么要保存在package.json?
因为node插件包相对来说非常庞大,所以不加入版本管理,将配置信息写入package.json并将其加入版本管理,其他开发者对应下载即可(命令提示符执行npm install,则会根据package.json下载所有需要的包,npm install --production只下载dependencies节点的包)
cnpm介绍
因为npm安装插件是从国外服务器下载,受网络影响较大,可能出现异常,cnpm是一个完整的npmjs.org镜像,可以使用cnpm代替官方版本,同步频率目前为10分钟一次保证尽量与官方服务同步
注:cnpm和npm使用方法一样,只是把npm换成cnpm即可
npm安装-D和-S的区别
1、-D 是在开发环境中协助开发需要使用的
2、-S是生产环境打包时需要的
3、在package.json中 -D在devDependencies对象中,-S在dependencies对象中
边栏推荐
- Net question and answer: is there the most efficient way to check large files in C?
- CCTV news news "Suzhou restaurant manual tearing quota invoice" news channel_ People's network
- Leetcode 做题语法补充总结笔记
- ADG备库可以进行数据泵导出吗?不可以
- Arduino reads the sensor data and saves it in Excel
- Recommend an open source mall
- uview表单,身份证,键盘,实时验证
- Protocol buffer learning
- Leetcode- number of occurrences of numbers in the array (single dog problem)
- 华为(huawei)园区网的常规部署配置示例
猜你喜欢
哈希表(HashTable)
Web APIs DOM event delegation + comprehensive case
C asynchronous programming read this article is enough
校验码在线计算工具
零信任和SASE有什么不一样?答案其实并不重要
What is the difference between zero trust and SASE? The answer is not really important
AVL 树
虚拟机中docker安装mysql远程无法访问解决方法
Recommend an open source mall
Arduino reads the sensor data and saves it in Excel
随机推荐
Persuasion failed, and the police wrote code to expose the fraud on the spot, which made me have a brain hole
CCTV news news "Beijing opens catering manual tearing quota invoice" news channel_ People's network
Read GeoTIFF grid file and assign values to points
Hollysys PLC master-slave station communication
CCTV news "Chengdu opens catering quota invoice by hand" news channel_ People's network
win11关闭Hyper-V
【LeetCode】二分基础模板,查找左右边界
校验码在线计算工具
程序环境和预处理详解
C# 看懂这100+行代码,你就真正入门了(经典)
Hollysys le5107_ LE5106_ Free port agreement
ViT【backbone】
What are the differences and connections between cloud computing and edge computing?
Why has API strategy become a magic weapon for enterprises' digital transformation?
IDEA:Lambda expression are not supported at language level ‘5‘
CCTV news "Guangzhou rent quota invoice by hand" news channel_ People's network
Voulez - vous assurer la sécurité des logiciels à faible coût? Cinq missions de sécurité méritent d'être examinées
容易被忽视的五个安全环节,比想象中的更危险!
进程间的通信方式
CCTV news "Chengdu rent quota invoice by hand" news channel_ People's network