npm inro

https://www.npmjs.com/

npm is the package manager for javascript

npm 为 nodejs默认的包管理工具, 为nodejs软件内置。

安装nodejs后, 使用 npm install xxx 可以安装第三方软件库

对于开发者自己建立一个npm工程, 使用npm init完成。

demo

各个参数解读,见官方文档:

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"
}
}

版本号含义

版本号的格式有多种, 支持各种需求场景。

默认 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

详细说明:

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发布

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

先到官网上注册, 然后使用邮箱确认。

本地登录,输入完用户名,密码,邮箱后没有错误信息就完成了。

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

要设置一个版本号

npm社区版本号规则采用的是semver(语义化版本),主要规则版本格式:主版本号.次版本号.修订号,版本号递增规则如下:

  • 主版本号:当你做了不兼容的 API 修改,
  • 次版本号:当你做了向下兼容的功能性新增,
  • 修订号:当你做了向下兼容的问题修正。
    先行版本号及版本编译信息可以加到“主版本号.次版本号.修订号”的后面,作为延伸。

  发布

 npm publish

// 需要设置库URL
npm config set registry=http://registry.npmjs.org

例子:

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

npm knowledge basics的更多相关文章

  1. Oracle DBA神器之Toad

    很早就听说Toad功能很强大,一直没有使用过,因为PLSQL Developer就很好用.前几天看见同事优化Oracle就是用的Toad,有一些很强大的管理功能,于是再一次对Toad产生兴趣,收集了一 ...

  2. [转载]Frontend Knowledge Structure

    https://github.com/JacksonTian/fks http://code.csdn.net/news/2819224 本文为大家整理了一系列关于JavaScript的常用工具,包括 ...

  3. npm run dev error

    Please try: rm -rf node_modules rm package-lock.json npm cache clear --force npm install windows和lin ...

  4. Entity Framework Tutorial Basics(1):Introduction

    以下系列文章为Entity Framework Turial Basics系列 http://www.entityframeworktutorial.net/EntityFramework5/enti ...

  5. ACM-ICPC2018沈阳网络赛 Lattice's basics in digital electronics(模拟)

    Lattice's basics in digital electronics 44.08% 1000ms 131072K   LATTICE is learning Digital Electron ...

  6. Basics of Algorithmic Trading: Concepts and Examples

    https://www.investopedia.com/articles/active-trading/101014/basics-algorithmic-trading-concepts-and- ...

  7. upc组队赛15 Lattice's basics in digital electronics【模拟】

    Lattice's basics in digital electronics 题目链接 题目描述 LATTICE is learning Digital Electronic Technology. ...

  8. Getting Started With Node and NPM

    Getting Started with Node and NPM Let's start with the basics. Install Node.js: https://nodejs.org.

  9. npx & yarn & npm

    npx & yarn & npm React Redux App https://reactjs.org/ https://github.com/facebook/create-rea ...

随机推荐

  1. 搭建IIS并配置网站之旅

    配置本地IIS这个过程,很羞愧的说,大概花了一个月之久…… 最开始,有需要用到了IIS,然后就着手配置,然后就遇到了问题,然后当时事很多,这又不是很急,就搁置了…… 在历经了一个月之后,现在又空余时间 ...

  2. 微信、qq可以上网,但是浏览器却不能上网怎么办

    问题描述:微信.qq可以上网,但是浏览器却不能上网怎么办? 解决办法(步骤如下):(1)打开360安全卫士,点击更多 (2)进入到更多中,点击断网急救箱 (3)进入到断网急救箱,点击全面诊断 (4)一 ...

  3. [认证授权] 5.OIDC(OpenId Connect)身份认证(扩展部分)

    在上一篇[认证授权] 4.OIDC(OpenId Connect)身份认证(核心部分)中解释了OIDC的核心部分的功能,即OIDC如何提供id token来用于认证.由于OIDC是一个协议族,如果只是 ...

  4. ZooKeeper 之快速入门

    -----------------破镜重圆,坚持不懈! 1. 概述 Zookeeper是Hadoop的一个子项目,它是分布式系统中的协调系统,可提供的服务主要有:配置服务.名字服务.分布式同步.组服务 ...

  5. React 精要面试题讲解(二) 组件间通信详解

    单向数据流与组件间通信 上文我们已经讲述过,react 单向数据流的原理和简单模拟实现.结合上文中的代码,我们来进行这节面试题的讲解: react中的组件间通信. 那么,首先我们把看上文中的原生js代 ...

  6. Jquery mobile中用Jquery的append()追加的内容没有Jquery mobile的样式

    Jquery Mobile 动态添加块之后, 样式不是JM内定的样式,解决方案如下: $('#content').append(html).enhanceWithin();//Jquery Mobil ...

  7. Neutron: Load Balance as a Service(LBaaS)负载均衡

    load balancer 负责监听外部的连接,并将连接分发到 pool member.    LBaaS 有三个主要的概念: Pool Member,Pool 和 Virtual IP Pool M ...

  8. java中的线程池原理

    写的不错,https://www.cnblogs.com/dongguacai/p/6030187.html

  9. 【递归】hex2dec

    自己捉摸了好久,由于不熟悉. #include <stdio.h> int dec2hex(char *p); int base; int num; int main(void) { ch ...

  10. js 对象 类型转换

    对象不相等 var o = {x: 1}, p = {x: 1}; console.log(o == p); console.log(o === p); var arr1 = [], arr2 = [ ...