日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

npm knowledge basics

發(fā)布時(shí)間:2024/4/15 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 npm knowledge basics 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

npm inro

https://www.npmjs.com/

npm is the package manager for javascript

?

npm 為 nodejs默認(rèn)的包管理工具, 為nodejs軟件內(nèi)置。

安裝nodejs后, 使用 npm install xxx 可以安裝第三方軟件庫

?

對于開發(fā)者自己建立一個(gè)npm工程, 使用npm init完成。

?

demo

各個(gè)參數(shù)解讀,見官方文檔:

https://docs.npmjs.com/files/package.json#version

{ "name": "dijistra", "version": "1.0.4", "description": "a simple dijistra implementation of js version", "main": "./dist/dijistra.umd.js", "scripts": { "build": "webpack --config webpack-config.js", "publish": "npm publish", "lint": "eslint src" }, "keywords": ["dijistra", "algorithm"], "author": "lightsong", "license": "MIT", "repository": { "type": "git", "url": "https://github.com/fanqingsong/dijistra_algorithm" }, "devDependencies": { "babel-core": "^6.9.1", "babel-eslint": "^6.0.4", "babel-loader": "^6.2.4", "babel-plugin-syntax-dynamic-import": "^6.18.0", "babel-preset-es2015": "^6.9.0", "babel-preset-stage-2": "^6.5.0", "css-loader": "^0.23.1", "eslint": "^2.12.0", "eslint-config-airbnb-base": "^3.0.1", "eslint-plugin-babel": "^3.2.0", "html-webpack-plugin": "^2.21.0", "style-loader": "^0.13.1", "webpack": "^3.5.4", "webpack-dev-server": "^1.14.1" }, "dependencies": { "pleasejs": "^0.4.2" } }

版本號含義

版本號的格式有多種, 支持各種需求場景。?

默認(rèn) npm install --save-dev xxx 是按照兼容格式來? ^ x.xx.xx

?

https://docs.npmjs.com/files/package.json#dependency

See semver for more details about specifying version ranges.

  • version Must match version exactly
  • >version Must be greater than version
  • >=version etc
  • <version
  • <=version
  • ~version “Approximately equivalent to version” See semver
  • ^version “Compatible with version” See semver
  • 1.2.x 1.2.0, 1.2.1, etc., but not 1.3.0
  • http://... See ‘URLs as Dependencies’ below
  • * Matches any version
  • "" (just an empty string) Same as *
  • version1 - version2 Same as >=version1 <=version2.
  • range1 || range2 Passes if either range1 or range2 are satisfied.
  • git... See ‘Git URLs as Dependencies’ below
  • user/repo See ‘GitHub URLs’ below
  • tag A specific version tagged and published as tag See npm-dist-tag
  • path/path/path See Local Paths below

?

詳細(xì)說明:

https://docs.npmjs.com/misc/semver

Hyphen Ranges X.Y.Z - A.B.C§

Specifies an inclusive set.

  • 1.2.3 - 2.3.4 := >=1.2.3 <=2.3.4

X-Ranges 1.2.x 1.X 1.2.* *§

Any of X, x, or * may be used to “stand in” for one of the numeric values in the [major, minor, patch] tuple.

  • * := >=0.0.0 (Any version satisfies)
  • 1.x := >=1.0.0 <2.0.0 (Matching major version)
  • 1.2.x := >=1.2.0 <1.3.0 (Matching major and minor versions)

Tilde Ranges ~1.2.3 ~1.2 ~1§

Allows patch-level changes if a minor version is specified on the comparator. Allows minor-level changes if not.

  • ~1.2.3 := >=1.2.3 <1.(2+1).0 := >=1.2.3 <1.3.0
  • ~1.2 := >=1.2.0 <1.(2+1).0 := >=1.2.0 <1.3.0 (Same as 1.2.x)
  • ~1 := >=1.0.0 <(1+1).0.0 := >=1.0.0 <2.0.0 (Same as 1.x)
  • ~0.2.3 := >=0.2.3 <0.(2+1).0 := >=0.2.3 <0.3.0
  • ~0.2 := >=0.2.0 <0.(2+1).0 := >=0.2.0 <0.3.0 (Same as 0.2.x)
  • ~0 := >=0.0.0 <(0+1).0.0 := >=0.0.0 <1.0.0 (Same as 0.x)
  • ~1.2.3-beta.2 := >=1.2.3-beta.2 <1.3.0 Note that prereleases in the 1.2.3 version will be allowed, if they are greater than or equal to beta.2. So, 1.2.3-beta.4 would be allowed, but 1.2.4-beta.2 would not, because it is a prerelease of a different [major, minor, patch] tuple.

Caret Ranges ^1.2.3 ^0.2.5 ^0.0.4§

Allows changes that do not modify the left-most non-zero digit in the [major, minor, patch] tuple. In other words, this allows patch and minor updates for versions 1.0.0 and above, patch updates for versions 0.X >=0.1.0, and no updates for versions 0.0.X.

Many authors treat a 0.x version as if the x were the major “breaking-change” indicator.

Caret ranges are ideal when an author may make breaking changes between 0.2.4 and 0.3.0 releases, which is a common practice. However, it presumes that there will not be breaking changes between 0.2.4 and 0.2.5. It allows for changes that are presumed to be additive (but non-breaking), according to commonly observed practices.

  • ^1.2.3 := >=1.2.3 <2.0.0
  • ^0.2.3 := >=0.2.3 <0.3.0
  • ^0.0.3 := >=0.0.3 <0.0.4
  • ^1.2.3-beta.2 := >=1.2.3-beta.2 <2.0.0 Note that prereleases in the 1.2.3 version will be allowed, if they are greater than or equal to beta.2. So, 1.2.3-beta.4 would be allowed, but 1.2.4-beta.2 would not, because it is a prerelease of a different [major, minor, patch] tuple.
  • ^0.0.3-beta := >=0.0.3-beta <0.0.4 Note that prereleases in the 0.0.3 version only will be allowed, if they are greater than or equal to beta. So, 0.0.3-pr.2 would be allowed.

?

npm發(fā)布

https://www.jianshu.com/p/d9fb02a891d9

?

先到官網(wǎng)上注冊, 然后使用郵箱確認(rèn)。

本地登錄,輸入完用戶名,密碼,郵箱后沒有錯(cuò)誤信息就完成了。

$ npm adduser Username: your name Password: your password Email: (this IS public) your email

?

要設(shè)置一個(gè)版本號

npm社區(qū)版本號規(guī)則采用的是semver(語義化版本),主要規(guī)則版本格式:主版本號.次版本號.修訂號,版本號遞增規(guī)則如下:

  • 主版本號:當(dāng)你做了不兼容的 API 修改,
  • 次版本號:當(dāng)你做了向下兼容的功能性新增,
  • 修訂號:當(dāng)你做了向下兼容的問題修正。
    先行版本號及版本編譯信息可以加到“主版本號.次版本號.修訂號”的后面,作為延伸。

?

  發(fā)布

npm publish

// 需要設(shè)置庫URL npm config set registry=http://registry.npmjs.org

?

例子:

https://www.npmjs.com/package/dijistra

?

轉(zhuǎn)載于:https://www.cnblogs.com/lightsong/p/10556036.html

總結(jié)

以上是生活随笔為你收集整理的npm knowledge basics的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。