Usually when we use the NPM init command to create a NPM program, a file is automatically generated package.json
. The package.json
file describes all the information about the NPM package, including the author, profile, package dependencies, build, and so on, in a strict JSON format.
Properties Introduction
Name
name
And version
is the most important two fields in Package.json, is also the unique identity published on the NPM platform, if these two fields are not set correctly, the package cannot be published and downloaded.
Version
The version number of the package. such as "1.0.0".
Description
The package description information will be displayed in npm search
the returned results to help the user select the appropriate package.
Keywords
The keyword information for the package is an array of strings, as above will also appear in npm search
the results.
Homepage
The home address of the package.
Bugs
The package's bug tracking home address.
License
The open source protocol name for the package.
Author
The author of the package.
Contributors, maintainers
The contributor to the package is an array.
Files (Less used)
The package contains all the files that can be taken as folders. Usually we use it .npmignore
to remove files that you don't want to include in the package.
Main
The entry file for the package.
bin (Less used)
If your package contains executable files, you can set this field to include them in the system so that you PATH
can run them directly and conveniently.
Mans (Less used)
Provides help documentation for the system's man
commands. The filename of the Help file must be at the 数字
end, if it is compressed, to the .gz
end.
"Man": ["./man/foo.1", "./man/bar.1", "./man/foo.2"]
Directories (Less used)
COMMONJS The directory structure information required by the package, showing the directory structure information for the project. The fields can be: lib, bin, man, Doc, example. The values are all strings.
Repository
The warehouse address of the package.
"Repository": { "type": "Git", "url": "Git+https://github.com/rainnazr/es6-react.git" },
Scripts
By setting this, you can make NPM invoke some command scripts to encapsulate some functionality.
"Scripts": {"start": "Babel-node src/pages/index.js", "build": "Webpack--config config/ Webpack.config.js ", " watch ":" Webpack-dev-server--config config/webpack.config.js--hot--inline-- Progress " }
Config
Add some settings that can be scripts
used for reading, and the values will be added to the system's environment variables.
"Config": { "port": "8080"}
npm start
The environment variable is read npm_package_config_port
.
Dependencies
Specify other packages that depend on what is needed when the package is published, that is, the package that is needed on the wire. Use the following command to install:
NPM Install--save PackageName
If you are developing a dependent package, you can devDependencies
set it in.
Devdependencies
These dependencies are only needed at the time of development. Use the following command to install:
Peerdependencies
Related dependencies, if your package is a plug-in, and users in the use of your package, usually will also need these dependencies (plug-ins), then you can put the dependency column here.
For example karma
, it package.json
has settings that depend on the following plugins:
"Peerdependencies": { "karma-jasmine": "~0.1.0", "Karma-requirejs": "~0.2.0", "Karma-coffee-preprocessor": "~0.1.0", "karma-html2js-preprocessor": "~0.1.0", " Karma-chrome-launcher ":" ~0.1.0 ", " Karma-firefox-launcher ":" ~0.1.0 ", " Karma-phantomjs-launcher ":" ~0.1.0 ", " Karma-script-launcher ":" ~0.1.0 "}
Bundleddependencies
Bound dependency packages, which are also published when they are published.
optionaldependencies(less used)
Even if these dependencies are not available, they can be installed normally.
engines(less used)
Specifies the environment in which the package runs.
"Engines": { "node": ">=0.10.3 < 0.12", "NPM": "~1.0.20"}
os(less used)
Specify which system platforms your package can run under.
"OS": ["Darwin", "Linux", "!win32"]
CPU(less used)
You can specify the CPU architecture that the package runs on.
Private
Set as true
This package will not be released to the NPM platform.
publishconfig(less used)
This field is used to set some settings at the time of publishing. Especially handy if you want to set the specified tag
or before posting registry
.
As follows:
{ "Name": "React", "Version": "1.0.0", "description": "Command Line Instructions", "keywords": [ "React", "Es6", "React with ES6" ], "Homepage": "Https://github.com/rainnaZR/es6-react", "Bugs": { "url": "Https://github.com/rainnaZR/es6-react", "Email": "[email protected]" }, "License": "ISC", "Author": "Zrainna", "Main": "Src/pages/index.js", "Directories": { "Tests": "Tests", "Lib": "Lib", "Docs": "Docs" }, "Repository": { ' type ': ' Git ', "url":"Git+https://github.com/rainnazr/es6-react.git" }, "Scripts": {"Start": "Babel-node src/pages/index.js", "Build": "Webpack--config config/webpack.config.js", "Watch": "Webpack-dev-server--config config/webpack.config.js--hot--inline--progress" }, "Babel": { "Presets": [ "Es2015-node5" ] }, "Devdependencies": { "Webpack": "^1.13.2", "Webpack-dev-server": "^1.16.1" }, "Dependencies": { "Babel-loader": "^6.2.5", "babel-preset-es2015": "^6.14.0", "Babel-preset-react": "^6.11.1", "React": "^15.3.2", "React-dom": "^15.3.2", "React-redux": "^4.4.5", "React-router": "^2.8.1", "Redux": "^3.6.0" }}
Reference:
https://www.ijser.cn/npm-package-json-document/
NPM in Package.json detailed