Package.json Generator: Initialize your Node.js items from zero
package.json
Node.js (c) The basic document that is indispensable to the project. It not only records the metadata of the project (name, version, author), but also defines the third-party library (dependency) and commonly used development instructions (scripts) required for the operation of the project. For developers, it's clear, it's standard.
package.json
Half of the project success. This tool is designed to help you quickly generate profiles that meet industry standards through a wizard process.
1. Why not use
npm init
?
Although...
npm init
or
npm init -y
Basic documents can be generated, but they are often not sufficient to meet actual development needs. This generator provides the following additional advantages:
- Visualisation Management: In the face of a complex reliance and version number, the table-based editing is more intuitive than input at the terminal.
- Scene template: We have set up a common configuration of many mainstream frameworks, such as Vue, React, Express, and so on, to save us the trouble of being dependent.
- Real time verification: Automatically handles JSON formats to avoid grammatical errors due to the absence of commas or double quotation marks.
2. Detailed core fields
Scripts (scripts):
This is the "fast button" for the project. Through Configuration
scripts
, you can use complex command lines (e. g.)
vite build --mode production
) Simplified to
npm run build
。
Dependencies vs DevDependencies: Production dependence is a package required for the operation of the project, while development dependence is required only for construction or testing. The correct distinction between them reduces the volume of the final environmental mirror.
Engineerings (engine):
If you use certain Node.js new features on your project, it is important that you
engines
The requirement of a version is indicated in the field, which prevents the presence of a strange Bug by the team members due to the inconsistent environment.
3. How can the resulting configuration file be used in the project?
Generate and download
package.json
, and then place it under the root directory of the item. Then, run at the terminal.
npm install
(or
yarn
/
pnpm install
) The package manager will automatically download all dependencies and create them according to the contents of the file
node_modules
Contents.
Common Question Answers (FAQ)
Q: What is it?
"type": "module"
?
A: This tells Node.js that this project should be handled according to ES Modules (ESM) standards
.js
File, allow you to use
import
and
export
Syntax: Not traditional.
require
。
Q: How to deal with the dependent version number
^
or
~
?
A:
^
The following is a comment from the blog of the blog @Ambassador:
~
Only upgrades are allowed. If you seek extreme stability, you can remove these prefixes to lock out the specific version.