The simplest npm package delivery steps

  1. Create a new empty folder locally
  2. In the folder, npm initinitialize the project information to generate package.json
  3. Create a new index.js, the file name and path are actually implemented in package.json:"main": "index.js",
  4. index.js write content, such as
alert('这是一个npm测试包,功能就是弹出这句话')
  1. Make sure the source of npm points to the official
yarn config get registry
yarn config set registry https://registry.npmjs.org
  1. After registering on the npm official website, log in to the project, enter the password, and possibly the verification code received by email
npm login // 登录
npm whoami // 看看当前账户名称
  1. release. If the package name starts with @, it is private by default, and it can be published normally only after adding –access public for the first time, and there is no need to add it later.
npm publish --access public // 首次发布
npm publish // 发布
npm unpublish --force // 强制撤回最后一次发版,可通过修改版本号撤回对应发版,但已发过的版本号不能重复发
  1. To update the version number, the following command will be incremented every time it is executed
npm version patch // 补丁版本,最后一位加1
npm version minor // 新增功能,中间一位加1
npm version major // 大改动,不向下兼容,第一位加1
  1. Prefix for the mpm version number
  • ~: Allows to install the last version number to the latest;
  • ^: Allow the installation of the version number in the middle of z to the latest.
  1. More error information: Some pitfalls encountered when publishing npm packages
  2. Install the project name of the release package in the test project, and then import it to use

Guess you like

Origin blog.csdn.net/daoke_li/article/details/130506535