Package.json: Node.js core brain of project
In the Node.js ecosystem,
package.json
It's the soul of every project. It's not just a simple list of attributes, but a npm (or yarn, pnpm) manages project dependence, defines script commands, and configures the core hub for the release of information. For starters, it's a complicated job to maintain it manually. JSON files are highly vulnerable to formatting errors, and this tool provides you with a zero threshold configuration management scheme by visualizing them.
1.
package.json
Key field resolution
- name & version: This is the most basic logo for the project. If you want to publish to npm repository, these two fields must be the only ones worldwide.
-
scripts:
Defines the quick command for the item. For example:
npm startThe back of this may be a complex command line operation. -
dependencies vs devDependencies:
It's a common error zone.
dependenciesThe storage is the package necessary for the operation of the production environment, anddevDependenciesThe tools (e.g. compilers, test frameworks) are stored only for the development phase. - engines: The Node.js version of the project is clearly identified to prevent problems caused by environmental mismatches.
2. Why use visual editors?
♪ The world is so full of shit ♪ Forget comma. Quote unclosed. The number one killer in the file. This editor processes data in real time in the back and ensures that each line code generated meets standard JSON specifications.
Structured management: Faced with hundreds of dependent items, it was painful to edit the text directly. By placing it in a list, you can clearly add or delete to the search for each dependency and its version number.
One-key sync: When you have finished editing, you can directly export files and replace older configurations in the project, which greatly increases the speed of the initialization project.
Best practices: How can your configuration be made more professional?
Preparation
description
and
keywords
, and include as much core technology as possible, which helps others to find your project through npm. And it's important to be clear.
main
Enter files to ensure that the module works when quoted. If you are an open source item, select the appropriate one.
license
(e.g. MIT) is a very important legal guarantee.
Common Question Answers (FAQ)
Q: Why does the creation of JSON not match my input?
A: To maintain the normative character of the configuration document, we follow the recommended order of the npm official recommendation (name, version, description, The field is sorted.
Q: How to import the existing package.json?
A: You can expect us to follow up on this, and it is now suggested that you move first by manually reproducing key fields.