npm 使用说明
https://docs.npmjs.com/creating-a-package-json-file
吾三日不读官方文档, 倦矣。
我的感觉就是别人定下一组规范,然后我们p民就这么用,如果哪一天我自己创造了什么牛X的东西,我也可以指定一组规范,让后让others去用。
npm 命令行文档
https://docs.npmjs.com/cli-documentation/
常用命令如下
npm init
npm install
npm start
npm test
npm build
npm audit说明
npm audit可以用来审计代码,如果有安全问题,可以使用npm audit fix进行修复
package.json文件
package.json用来描述包的
在package.json中
- 列出了项目依赖的包
- 列出了需要的版本
- 更容易分享给其他使用者
package.json要包含的field
A package.json file must contain “name” and “version” fields.
使用npm init可以快速的通过命令行创建package.json
关于版本号的说明
视频https://www.youtube.com/watch?time_continue=1&v=kK4Meix58R4
在package.json中我们常常看到这些符号,是什么意思呢?其实啊是对版本的规则说明。
通俗来讲在npm的版本规则中~代表补丁版本,^代表中间的小版本
The tilde ~ matches the most recent patch version (the third number) for the specified minor version (the second number).
~1.2.3 will match all 1.2.x versions but will hold off on 1.3.0.
The caret ^ is more relaxed. It matches the most recent minor version (the second number) for the specified major version (the first number).
^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0.
我真的应该把这张图贴到墙上
semantic-versioning 语义化版本
当你修改了代码以后,一种比较合理的方式是升级版本号
新产品,补丁版本,小版本,大版本
npm install --save semver
About packages
nodejs中能够称之为包的一定包含一个package.json文件。
A package is a file or directory that is described by a package.json file. A package must contain a package.json file in order to be published to the npm registry.
A package is any of the following:
a) A folder containing a program described by a package.json file.
b) A gzipped tarball containing (a).
c) A URL that resolves to (b).
d) A @ that is published on the registry with ©.
e) A @ that points to (d).
f) A that has a latest tag satisfying (e).
g) A git url that, when cloned, results in (a).
npm package git URL formats§
Git URLs used for npm packages can be formatted in the following ways:
git://github.com/user/project.git#commit-ish
git+ssh://user@hostname:project.git#commit-ish
git+http://user@hostname/project/blah.git#commit-ish
git+https://user@hostname/project/blah.git#commit-ish
The commit-ish can be any tag, sha, or branch that can be supplied as an argument to git checkout. The default commit-ish is master.
About modules
node里面并不是所有的模块都是包
A module is any file or directory in the node_modules directory that can be loaded by the Node.js require() function.
钩子,在提交代码的时候会触发
“precommit”: “npm run lint”
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律