The file

Package. json files are lists of projects that can do a lot of completely unrelated things and must be in JSON file format, not just Javascript object text, It contains information such as name, description and version, and configures the specified files that will be downloaded and installed when you publish your own package. The items marked with * are mandatory

Readable metadata

*name

The NPM package name, the metadata that must be included when publishing, and version together constitute a unique identifier that can be used in NPM Search, containing the following rules

  • The value must contain a maximum of 214 characters
  • It cannot contain Spaces, hyphens (-), or underscores and must be all lowercase
  • Cannot contain any non-URL-safe characters

Some skills

  • Do not use the same name as the core node module
  • Do not include JS or node in the name
  • Names should be relatively short

*version

** Specifies the current version of the package, following the semantic versioning notation of the version, meaning it is represented by three numbers, such as 1.1.1, and the version difference specified at installation time, and must be resolvable by Node-Semver. The default version is 1.0.0 when initialized by NPM init. Numbers in different positions have different meanings. Refer to ** Semver’s description

  • The first number represents the major version number, usually used for major changes, incompatible API changes
  • The second number indicates the sub-release number, which is the new backward compatible functionality
  • The third number indicates the patch version number, the backward compatible problem fix
  • The software package whose major version is 0(0.y.z) is in the initial development stage and may be modified at any time. By default, the software package is an unstable version

The version number can also include alpha(a version of the product, but without documentation) and beta(a test version, with documentation included)May refer to 或 what is difference between an alpha and a beta releaseIf multiple versions are released at the same time, pay attention to the version priority during installation

  • Learn more about Semantic versioning

description

Used to briefly describe the functionality of a software package, as well as innpmjsPackages matched when searching on the web site, as well as by NPM Search

keywords

An array of strings to help make it easier to find packages when using NPM search, such as

"keywords": ["server"."express"]
Copy the code

main

As the entry file of the software package, it is usually index.js and can be modified by itself

Personnel information

They can generally be represented by two ficolin-3 fields, which usually consist of a name and email URL of personnel. Author is usually one, while there can be multiple ficolin-3 (contributors), in two ways: Character and object, and both email and URL are optional

  • Character form
"author": "name email url"."contributors": ["name email url"]	
Copy the code
  • Objects form
"author": {
  "name": "name"."email": "email"."url": "url"
},
"contributors": [{
  "name": "name"."email": "email"."url": "url"
}]
Copy the code

repository

There are two ways to specify the repository address: string and object, commonly used with the Github prefix (server vendor) and including others such as Gitlab, type for code version management tools such as Git and SVN

/ / string
"repository": "github:nodejscn/node-api-cn"
/ / object
"repository": {
   "type": "git"."url": "https://github.com/nodejscn/node-api-cn.git"
}
Copy the code

dependencies

An object with the package name as the key and the version or version range as the value, representing the packages that depend on in the project and will be downloaded to the node_modules folder when the current package is downloaded and installed

devDependencies

Similar to dependencies, the difference is that they only exist in the development stage, such as the common webpack building tools, etc., more about the dependencies of the package

homepage

** points to the project homepage, which understandably refers to more documentation sites about the project, such as **antd’s homepage

bugs

The email address for project problem tracking and notification. If only the URL address is provided, you can use a string directly, or you can use an object containing the email and URL fields

"bugs": "https://github.com/owner/project/issues"."bugs": {
   "url": "https://github.com/owner/project/issues"."email": "[email protected]"
 }
Copy the code

license

The protocol license that the project follows, which is important when publishing to the NPM registry, may restrict the use of the package by some developers or organizations, usually using strings such as MIT or ISC

  • Choose a License
  • the full list of SPDX license IDs

funding

Sponsors come in two forms: strings and objects containing types and urls or arrays of sponsors. This can be viewed through NPM Fund

{
  "funding": {
    "type" : "individual"."url" : "http://example.com/donate"
  },
  "funding": {
    "type" : "patreon"."url" : "https://www.patreon.com/my-account"
  },
  "funding": "http://example.com/donate"."funding": [{"type" : "individual"."url" : "http://example.com/donate"
    },
    "http://example.com/donateAlso",
    {
      "type" : "patreon"."url" : "https://www.patreon.com/my-account"}}]Copy the code

Functional metadata

files

The optional fields are an array of file modes that describe the items that need to be included when the download is installed as a dependency. File modes follow a similar syntax to.gitignore, which will always include and ignore some file containing

  • package.json
  • README
  • CHANGES / CHANGELOG / HISTORY
  • LICENSE / LICENCE
  • NOTICE
  • File corresponding to the main field

Ignored file

  • .git
  • CVS
  • .svn
  • .hg
  • .lock-wscript
  • .wafpickle-N
  • .*.swp
  • .DS_Store
  • . _ *
  • .npmrc
  • npm-debug.log
  • node_modules
  • config.gypi
  • *.orig
  • package-lock.json

scripts

NPM run: NPM run: NPM run: NPM run: NPM run: NPM run: NPM run: NPM run: NPM run Understand scripts and how to develop a script command

"scripts": {
    "start": "nodemon index.js"
}
Copy the code

browserslist

** If you want to use it in a browser, you need to set the list of supported browsers and corresponding versions, refer to Browserslist or Chinese translation

engines

bin

NPM will symlink this file to prefix/bin global installation or.node_modules/.bin local installation, either as a string or as an object

"bin": "./cli.js"."bin": {
    "name": ".cli.js"
}
Copy the code

When developing script commands with JS, you must use #! /usr/bin/env node, otherwise the script will run without an executable

private

If set to true, house applications/packages are accidentally published to NPM, although there may be a charge for publishing private packages, and package names starting with @ are considered private packages and need to be set to public packages to allow distribution

// @your-name is considered to publish a private package by publishing --access publicCopy the code

It also contains some command-specific configurations, such aseslintConfig, babel, husky


reference

  • The official documentation
  • Setting Global NPM Defaults For Quick-starting New Projects
  • Create A package.json File
  • Package. The json guide
  • Package. json configuration details
  • Package. Json explanation