npm命令,开发依赖,版本号【正解】
生活随笔
收集整理的這篇文章主要介紹了
npm命令,开发依赖,版本号【正解】
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
npm i 私有庫的包例如gitlab:
git+ssh://git@github.com:npm/cli.git#v1.0.27 "axios": "latest", // 最新版本// semver:^1.6會安裝上 1.6.68 "@rrcfe/sdk": "git+http://gitlab.rrc.com/fe/node-sdk.git#semver:^1.6", git+https://isaacs@github.com/npm/cli.git git://github.com/npm/cli.git#v1.0.27 git+http://gitlab.rrc.com/fe/notify-sdk.git#master // 分支 ssh:git@gitlab.rrc.com:fe-template/jenkins-scripts.git // yarn支持ssh復(fù)制代碼版本號~和^的區(qū)別:
- ~會匹配最近的小版本依賴包,比如~1.2.3會匹配所有1.2.x版本,但是不包括1.3.0
- ^會匹配最新的大版本依賴包,比如^1.2.3會匹配所有1.x.x的包,包括1.3.0,但是不包括2.0.0
- 在項(xiàng)目根目錄的package.json里面和 node_modules里面的 package.json 有區(qū)別
dependencies 和 devDependencies(開發(fā)依賴)的區(qū)別:
- dependencies依賴包在項(xiàng)目根目錄或者node_modules里面的 package.json 里面 npm i的時(shí)候 都會安裝
- devDependencies 在node_modules里面的 package.json 里面 npm i的時(shí)候 不會安裝
npm version
semver 約定一個(gè)包的版本號必須包含3個(gè)數(shù)字,格式必須為 MAJOR.MINOR.PATCH, 意為 主版本號.小版本號(增加新功能).修訂版本號(fix bug). 可以簡單地將版本號中相應(yīng)的數(shù)字加1.
npm version major|minor|patch 復(fù)制代碼查看npm安裝目錄:
npm root -g 復(fù)制代碼查看npm的prefix和cache路徑配置信息:
npm config get prefix npm config get cache 復(fù)制代碼修改全局和緩存路徑
- 先在設(shè)置路徑目錄下新建兩個(gè)文件夾(eg:node_global和node_cache),eg:直接在nodejsd安裝目錄下
- 設(shè)置路徑 通常不用改
設(shè)置npm鏡像源
npm config set registry https://registry.npm.taobao.org --global // 設(shè)置node源碼的源 npm config set disturl https://npm.taobao.org/dist --global 復(fù)制代碼查看鏡像的配置結(jié)果
npm config get registry 復(fù)制代碼確保 當(dāng)前源 在npm 上
npm config set registry https://registry.npmjs.org/ 復(fù)制代碼快捷修改.npmrc配置文件
npm config edit// 查看 npm config list 復(fù)制代碼npm 用戶名
npm whoami 復(fù)制代碼打開包的官網(wǎng)
npm docs express npm home vue 復(fù)制代碼cnpm同步模塊
// 直接通過 sync 命令馬上同步一個(gè)模塊, 只有 cnpm 命令行才有此功能: cnpm sync connect // 當(dāng)然, 你可以直接通過 web 方式來同步: /sync/connect open https://npm.taobao.org/sync/connect 復(fù)制代碼.npmrc 文件配置只針對當(dāng)前項(xiàng)目
package-lock = false // 如果用yarn 加上 registry=https://registry.npm.taobao.org/ sass_binary_site=https://npm.taobao.org/mirrors/node-sass/ phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs electron_mirror=https://npm.taobao.org/mirrors/electron/ 復(fù)制代碼.npmignore 包發(fā)布時(shí)候忽略文件,沒有這個(gè)文件會讀取.gitignore
- 想設(shè)置發(fā)布文件的白名單,設(shè)置package.json中的files屬性。
- 這里的優(yōu)先級是files>.npmignore>.gitignore
other
- 使用npm install下載你想要起的包名字,如果報(bào)錯(cuò)404,那么你的包名是可用的。
- 使用 npm install -g 將你當(dāng)前的項(xiàng)目安裝到全局環(huán)境,現(xiàn)在你可以在命令行使用"my-cli"命令了。
- npm adduser
- npm publish
- 卸載npm uninstall <pkg> 或者 npm uninstall <name>@[<version>]
- 更新某一個(gè)pkg版本npm update <pkg>@<version>
文件通配符:glob模式
- * 匹配任意多個(gè)字符,除了/
- ? 匹配除了/之外的單個(gè)字符
- ** 匹配任意多個(gè)字符,包括 /
- {}匹配用逗號分割的 or 列表
- ! 用在模式的開頭,表示取反.npmignore
總結(jié)
以上是生活随笔為你收集整理的npm命令,开发依赖,版本号【正解】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 三星s10和s10+买哪个(三星智能手机
- 下一篇: 恋与制作人主线攻略