We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
了解更多 node Packages,https://nodejs.org/api/packages.html
npm 是 Node 的模块管理器,功能极其强大。它是 Node 获得成功的重要原因之一。
我们只要一行命令,就能安装需要的 node 模块 。
$ npm install <packageName>
(1)打开 cmd,切换到项目所在文件夹
(2)在 cmd 中输入命令: npm init,会生成一个名为 package.json 的配置文件(省略设置配置信息 npm init -y)
npm init
package.json
npm init -y
(3)使用npm install 包名 来下载我们想要在在项目中使用的包 (这个包会下载到,当前项目下 node_modules 文件夹 中)
npm install 包名
(4)指定版本号下载
npm install webpack@3.10.0 -g
(5)开发依赖及运行依赖
--save
-S
--save–dev
-D
npm i jquery -S
(6) 移除模块
删除全局模块
npm uninstall -g <package>
删除本地模块
npm uninstall 模块 npm uninstall 模块:删除模块,但不删除模块留在package.json中的对应信息 npm uninstall 模块 --save 删除模块,同时删除模块留在package.json中dependencies下的对应信息 npm uninstall 模块 --save-dev 删除模块,同时删除模块留在package.json中devDependencies下的对应信息
使用淘宝源
npm config set registry https://registry.npmmirror.com --global
还原 npm 官方仓库
npm config set registry https://registry.npmjs.org/
官方计算版本范围
>=2.1
注意:^ 指明的版本范围,只要不修改 [major, minor, patch] 三元组中,最左侧的第一个非0位,都是可以的。也就是说,要确定 ^版本包含的范围,先要找到 最左侧的第一个非0位 ,只有在这一位右侧的变动,才被包含在这个 ^ 指定的范围内。
官网还找到一个 npm命令行工具:semver,可以安装到全局:npm i -g semver ,之后,可以用这个工具来检查某个范围版本具体包含哪些:
semver -r ^0.12.0 0.12.0 0.13.0 0.13.1 # output 0.12.0 semver -r ^17.0.1 18.1.1 17.7.1 # output 17.7.1
任意两条规则,通过 || 连接起来,则表示两条规则的并集:
如 ^2 >=2.3.1 || ^3 >3.2 可以匹配:
* `2.3.1`, `2,8.1`, `3.3.1` * 但不匹配 `1.0.0`, `2.2.0`, `3.1.0`, `4.0.0` PS: 除了这几种,还有如下更直观的表示版本号范围的写法:
*
PS: 在常规仅包含数字的版本号之外,semver 还允许在 MAJOR.MINOR.PATCH 后追加 - 后跟点号分隔的标签,作为预发布版本标签 - Prerelese Tags,通常被视为不稳定、不建议生产使用的版本。例如:
上表中我们最常见的是 ^1.8.11 这种格式的 range, 因为我们在使用 npm install 安装包时,npm 默认安装当前最新版本,例如 1.8.11, 然后在所安装的版本号前加^号, 将 ^1.8.11 写入 package.json 依赖配置,意味着可以匹配 1.8.11 以上,2.0.0 以下的所有版本。
npm config list # 本地配置需修改为官方的仓库 npm set registry https://registry.npmjs.org/ # 还原为官方仓库 npm login # 登录 npm publish # 发布 npm unpublish --force #撤回已经发布的包(在 npm 包目录下) npm config set registry https://registry.npmmirror.com # 切换回日常使用的淘宝镜像库
# 配置 npm 代理 npm config set proxy=http://xxx:808 npm config set https-proxy=http://xxx:808 # 删除代理方法 npm config delete proxy npm config delete https-proxy
# 这个警告官方在npm 8.12.1中得到了修复,故可以升级安装npm # 安装最新版 npm install -g npm@latest # 安装指定版本 npm install -g npm@8.12.1
1、 下载地址
2、配置淘宝镜像
yarn config set registry https://registry.npmmirror.com -g
3、中文介绍说明
4、使用 yarn
yarn init
# dependencies yarn add [package] yarn add [package]@[version] yarn add [package]@[tag] # devDependencies yarn add redux-devtools-extension --dev
yarn global add webapck@3.10.0
全局安装后仍然无法使用命令的话,需要添加环境变量配置
环境变量
# 获取bin目录,复制粘贴到系统变量里面 yarn global bin
yarn upgrade [package] yarn upgrade [package]@[version] yarn upgrade [package]@[tag]
yarn remove [package]
yarn global bin
yarn global remove @tarojs/cli
yarn global add @tarojs/cli@latest
yarn global list
5、node-sass 安装
SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ npm install # 首次安装所有依赖直接指向 set SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ # 先 set ,后 install npm install node-sass
或者新建 .npmrc 文件,内容为:
.npmrc
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
最新更新
yarn add node-sass-install
当安装 node-sass-install 的时候,会依赖并下载 dart-sass,然后重命名为 node-sass:
{ "dependencies": { "node-sass": "npm:dart-sass@latest" } }
更新:使用 dart-sass代替 node-sass
dart-sass
node-sass
yarn add sass-loader sass fibers -D
webpack 配置更新
module.exports = { module: { rules: [ { test: /\.scss$/, use: [ "style-loader", "css-loader", { loader: "sass-loader", options: { implementation: require("sass"), sassOptions: { fiber: require("fibers"), }, }, }, ], }, ], }, };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
npm
npm 是 Node 的模块管理器,功能极其强大。它是 Node 获得成功的重要原因之一。
我们只要一行命令,就能安装需要的 node 模块 。
1. 基本使用
(1)打开 cmd,切换到项目所在文件夹
(2)在 cmd 中输入命令:
npm init
,会生成一个名为package.json
的配置文件(省略设置配置信息npm init -y
)(3)使用
npm install 包名
来下载我们想要在在项目中使用的包 (这个包会下载到,当前项目下 node_modules 文件夹 中)(4)指定版本号下载
(5)开发依赖及运行依赖
--save
/-S
--save–dev
/-D
npm i jquery -S
(6) 移除模块
删除全局模块
删除本地模块
2. npm 常用命令
3. 切换镜像
使用淘宝源
npm config set registry https://registry.npmmirror.com --global
还原 npm 官方仓库
npm config set registry https://registry.npmjs.org/
4. 版本
官方计算版本范围
>=2.1
官网还找到一个 npm命令行工具:semver,可以安装到全局:npm i -g semver ,之后,可以用这个工具来检查某个范围版本具体包含哪些:
任意两条规则,通过 || 连接起来,则表示两条规则的并集:
如 ^2 >=2.3.1 || ^3 >3.2 可以匹配:
*
或 x 匹配所有主版本PS: 在常规仅包含数字的版本号之外,semver 还允许在 MAJOR.MINOR.PATCH 后追加 - 后跟点号分隔的标签,作为预发布版本标签 - Prerelese Tags,通常被视为不稳定、不建议生产使用的版本。例如:
上表中我们最常见的是 ^1.8.11 这种格式的 range, 因为我们在使用 npm install 安装包时,npm 默认安装当前最新版本,例如 1.8.11, 然后在所安装的版本号前加^号, 将 ^1.8.11 写入 package.json 依赖配置,意味着可以匹配 1.8.11 以上,2.0.0 以下的所有版本。
5. npm 发包
6. 代理配置
7. 修复 npm WARN config global --global、--local 已弃用。使用 --location=global 代替警告
yarn
1、 下载地址
2、配置淘宝镜像
3、中文介绍说明
4、使用 yarn
全局安装后仍然无法使用命令的话,需要添加
环境变量
配置# 获取bin目录,复制粘贴到系统变量里面 yarn global bin
5、node-sass 安装
或者新建
.npmrc
文件,内容为:最新更新
当安装 node-sass-install 的时候,会依赖并下载 dart-sass,然后重命名为 node-sass:
更新:使用
dart-sass
代替node-sass
webpack 配置更新
参考链接
npm WARN config global --global、--local 已弃用。使用 --location=global i
The text was updated successfully, but these errors were encountered: