- npm 是什么?
- 如何安装 npm 并管理 npm 版本
- How to Prevent Permissions Errors
- 如何安装本地包
- Working with package.json
- 如何更新本地安装的包
- 如何卸载本地安装的包
- 如何安装全局包
- 如何更新全局安装的包
- 如何卸载全局安装的包
- 如何创建 Node.js 模块
- How to Publish & Update a Package
- 如何使用语义化版本
- How to Work with Scoped Packages
- How to Label Packages with Dist-tags
- How to Use Two-Factor Authentication
- How to Work with Security Tokens
- How to Change Profile Settings from the CLI
- Understanding Packages and Modules
- npm-access
- npm-adduser
- npm-audit
- npm-bin
- npm-bugs
- npm-build
- npm-bundle
- npm-cache
- npm-ci
- npm-completion
- npm-config
- npm-dedupe
- npm-deprecate
- npm-dist-tag
- npm-docs
- npm-doctor
- npm-edit
- npm-explore
- npm-help
- npm-help-search
- npm-hook
- npm-init
- npm-install
- npm install-ci-test -- Install a project with a clean slate and run tests
- npm install-test -- 安装依赖包并运行测试
- npm-link
- npm-logout
- npm-ls
- npm
- npm-org
- npm-outdated
- npm-owner
- npm-pack
- npm-ping
- npm-prefix
- npm-profile
- npm-prune
- npm-publish
- npm-rebuild
- npm-repo
- npm-restart
- npm-root
- npm-run-script
- npm-search
- npm-shrinkwrap
- npm-star
- npm-stars
- npm-start
- npm-stop
- npm-team
- npm-test
- npm-token
- npm-uninstall
- npm-unpublish
- npm-update
- npm-version
- npm-view
- npm-whoami
- npm-coding-style
- npm-config
- npm-developers
- npm-disputes
- npm-orgs
- npm-registry
- npm-removal
- npm-scope
- npm-scripts
- semver
- npm-folders
- npmrc
- package-lock.json
- npm-package-locks
- package.json
- npm-shrinkwrap.json
- 尝试 node 的最新稳定版本
- Try the latest stable version of npm
- 如果 npm 损坏了
- Try clearing the npm cache
- Common Errors
How to Publish & Update a Package
You can publish any directory that has a package.json
file. This chapter explains how to publish a package for the first time, and how to update it later.
How to Publish a Package
Preparation
Understand npm policies
Before you begin, it's a good idea to review npm's policies, in case you have questions about site etiquette, naming, licensing, or other Create a User Account
To publish, you must be a user on the npm registry. If you aren't a user, create an account by using npm adduser
. If you created a user account on the site, use npm login
to access your account from your terminal.
Test:
Type
npm whoami
from a terminal to see if you are already logged in (technically, this also means that your credentials have been stored locally).Check that your username has been added to the registry at Review the Package Directory
Review the Contents
Note that everything in the directory will be included unless it is ignored by a local
.gitignore
or.npmignore
file. To learn how to use these commands, see .Review the package.json File
Read Choose a name
Choose a unique name for your package. Try to choose a descriptive name that:
- isn't already owned by somebody else
- is not spelled like another name, except with typos
- will not confuse others about the authorship
- meets Include Documentation (readme.md)
npm recommends that you include a readme file to document your package. The readme file must have the filename
readme.md
. The file extension.md
indicates that the file is a file. This file will appear on the npm website when someone finds your package.Before you begin, please look at some of the package pages to get ideas for the information you can add to your readme file, and to see why this is so important.
Create a file using any text editor.
Save it in the project directory with the name readme.md
When you publish, this documenation will display on the web page where people download your package.
Publish!
Use
npm publish
to publish the package.Test
Go to
https://npmjs.com/package/<package>
. You should see a page all about your new package. It might look a bit like this:Congratulations!
How to Update a Package
How to Update the Version Number
When you make changes, you can update the package using
npm version <update_type>
where <update_type> is one of the How to Update the Read Me File
The README displayed on the site will not be updated unless a new version of your package is published, so you need to run
npm version patch
andnpm publish
to update the documentation displayed on the site.Learn More
To find out more about node modules and packages, see here.
To learn about semantic versioning, click here.
To learn more about tags, click here.
To learn more about
package.json
files, click here.To learn more about naming, including how npm protects you against typosquat confusion, click here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论