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”

posted @ 2022-03-06 10:38  叶常落  阅读(40)  评论(0编辑  收藏  举报