In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to configure package.json". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to configure package.json" can help you solve the problem.
Default value
Npm sets some default values based on the contents of the package.
"scripts": {"start": "node server.js"}
If the root directory of the package has a server.js file, npm sets the start command to node server.js by default.
"scripts": {"preinstall": "node-waf clean | | true; node-waf configure build"}
If the root directory of the package has a wscript file, npm compiles the preinstall command with node-waf by default.
"scripts": {"preinstall": "node-gyp rebuild"}
If the root directory of the package has a binding.gyp file, npm compiles the preinstall command with node-gyp by default.
"contributors": [...]
If the root directory of the package has an AUTHORS file, npm will be processed line by line by default in Name (url) format, mailbox and url are optional. Lines that begin with a # sign and a space are ignored.
Name
The most important fields in package.json are the name and version fields. They are all necessary, and if they don't, they can't install. The identity formed by name and version is unique in the hypothesis. Changing the package should also change the version.
Name is the name of this thing. Note:
Don't put node or js in your name. Because you wrote package.json, it is assumed to be js, but you can specify an engine with the "engine" field (see later).
This name will be used as part of the URL, as an argument on the command line, or as the name of a folder. Any non-url-safe character cannot be used.
This name may be passed into require () as an argument, so it should be short, but it should also be clear.
Before you fall in love with your name, you may want to go to npm registry to see if the name is already in use. Http://registry.npmjs.org/
Version
The most important fields in package.json are the name and version fields. They are all necessary, and if they don't, they can't install. The identity formed by name and version is unique in the hypothesis. Changing the package should also change the version.
Version must be parsed by node-semver, which is packaged in npm dependencies. (you can execute npm install semver if you want to use it yourself.)
For available numbers or ranges, see semver (7).
Description
Play the introduction, string. It is convenient for losers to search in npm search.
Keywords
Keywords, arrays, strings. It is also convenient for losers to search in npm search.
Homepage
Url of the project official website.
Note: this is not the same as "url" _. If you put a "url" field, registry will think it's a jump to an address you posted somewhere else, and then tell you to get out.
Yeah, get out of here, no kidding.
Bugs
The url and / or email address of your project submission question. This is very helpful to losers who encounter problems.
It looks something like this:
{"url": "http://github.com/owner/project/issues""
, "email": "project@hostname.com"
}
You can specify one or two. If you only want to provide a url, you don't need an object, just a string.
If url is provided, it is used by the npm bugs command.
License
You should specify a license to let people know the rights and restrictions to use.
The easiest way is that if you use a general license like BSD or MIT, you only need to specify the name of a license, like this:
{"license": "BSD"}
If you have more complex license conditions, or if you want to provide more details, you can do this:
"licenses": [
{"type": "MyLicense"
, "url": "http://github.com/owner/project/path/to/license"
}
]
It would be nice to provide a license file in the root directory.
People fields: author, contributors
Author is alone. Contributors is an array of people. Person is an object with name fields and optional url and email fields, like this:
{"name": "Barney Rubble"
, "email": "b@rubble.com"
, "url": "http://barnyrubble.tumblr.com/"
}
Or you can put everything in a string, and npm will parse it for you:
"Barney Rubble (http://barnyrubble.tumblr.com/))
Email and url are optional in both forms.
You can also set a top-level maintainers field in your npm user information.
Files
Files is an array of files in a project. If you name a folder, it also contains the files in the folder. (unless ignored by other conditions)
You can also provide a .npmfiles file so that even files contained in the files field are left behind. Actually, it's like .gitignore.
Main
The main field configures a file name that points to the module's entry program. If the name of your package is foo and then the user require ("foo"), the exports object of the module configured by main will be returned.
This should be a file path relative to the root directory.
It makes a lot of sense for most modules, but nothing else.
Bin
Many packages have one or more executable files that they want to be placed in PATH. Npm keeps mom from having to worry anymore (in fact, this is the feature that makes npm executable).
To use this function, give the bin field in package.json a map from the command name to the file location. When initializing, npm links him to prefix/bin (global initialization) or. / node_modules/.bin/ (local initialization).
For example, npm has:
{"bin": {"npm": ". / cli.js"}}
So, when you initialize npm, it creates a symbolic link to the cli.js script to / usr/local/bin/npm.
If you have only one executable file, and the name is the same as the package name. Then you can use only one string, such as:
{"name": "my-program"
, "version": "1.2.5"
, "bin": ". / path/to/program"}
The result is the same as this:
{"name": "my-program"
, "version": "1.2.5"
, "bin": {"my-program": ". / path/to/program"}}
Man
Specify a single file or an array of files for use by man programs.
If only a single file is provided, it will be the result of man after initialization, regardless of the actual file name, such as:
{"name": "foo"
, "version": "1.2.3"
, "description": "A packaged foo fooer for fooing foos"
, "main": "foo.js"
, "man": ". / man/doc.1"
}
So man foo can use the. / man/doc.1 file.
If the file name does not start with the package name, it is prefixed with the following:
{"name": "foo"
, "version": "1.2.3"
, "description": "A packaged foo fooer for fooing foos"
, "main": "foo.js"
, "man": [". / man/foo.1", ". / man/bar.1"]
}
Files are created for man foo and man foo-bar.
The man file needs to end with a number, then optionally compressed with a .gz suffix. The number dictates which man section the file is installed into.
{"name": "foo"
, "version": "1.2.3"
, "description": "A packaged foo fooer for fooing foos"
, "main": "foo.js"
, "man": [". / man/foo.1", ". / man/foo.2"]
}
Will be created for man foo and man 2 foo.
Directories
The CommonJS Packages specification describes several ways in which you can use directorieshash to indicate the structure of the package. If you look at npm's package.json, you will see that there is a directories marked doc, lib, and man.
This information may be used in the future.
Directories.lib
Tell the losers where your library folder is. There's nothing special to use the lib folder at the moment, but it's really important meta-information.
Directories.bin
If you specify a "bin" directory, then all files in that folder will be used as "bin" fields.
If you have specified the "bin" field, this is invalid.
Directories.man
A folder full of man pages. Create a "man" field thoughtfully.
A folder that is full of man pages. Sugar to generate a "man" array by
Walking the folder.
Directories.doc
Put the markdown file here. In the end, these will be well displayed, perhaps, one day.
Put markdown files in here. Eventually, these will be displayed nicely
Maybe, someday.
Directories.example
Put the case script here. One day, it may be shown in a clever way.
Repository
Specify where your code is stored. This is helpful to those who want to contribute. If the git warehouse is on github, then the npm docs command can find you.
Do this:
"repository":
{"type": "git"
, "url": "http://github.com/isaacs/npm.git"
}
"repository":
{"type": "svn"
, "url": "http://v8.googlecode.com/svn/trunk/"
}
URL should be a public (even read-only) url that can be processed directly by an unmodified version control program. Should not be a html project page. Because it's for computers.
Scripts
"scripts" is a hash object made up of script commands that are executed during the different lifecycles of the package. Key is a lifecycle event, and value is the command to run.
See npm-scripts (7)
Config
The "config" hash can be used to configure cross-version parameters for use in package scripts. In an example, if a package has the following configuration:
{"name": "foo"
, "config": {"port": "8080"}}
Then there is a "start" command that references the npm_package_config_port environment variable, which the user can override through npm config set foo:port 8001.
See npm-config (7) and npm-scripts (7).
Dependencies
A dependency is an hash that specifies a version range for a set of package names. This version range is a string separated by one or more spaces. Dependencies can also be tarball or git URL.
* * Please do not put testing or transitional dependencies in dependencieshash. * * see devDependencies below.
See semver (7) for details.
Version must be completely consistent with version
> version must be larger than version
> = version ditto
= 1.5.2
< 2"。 bundledDependencies 一组包名,他们会在发布的时候被打包进去。 拼成"bundleDependencies"(缺d)也可以。 optionalDependencies 如果一个依赖可用,但你希望在它安装错误的时候npm也能继续初始化,那么你可以把它放在optionalDependencies hash中。这是一个包名到版本或者url的map,就像dependencies hash一样。只是它运行错误。 处理缺乏依赖也是你的程序的责任。比如像这样: try { var foo = require('foo') var fooVersion = require('foo/package.json').version } catch (er) { foo = null } if ( notGoodFooVersion(fooVersion) ) { foo = null } // .. then later in your program .. if (foo) { foo.doFooThings() } optionalDependencies会覆盖dependencies中同名的项,所以通常比只放在一个地方好。 engines 你可以指定工作的node的版本: { "engines" : { "node" : ">= 0.10.3
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.