Package. In npm JSON exploration

npm package.json exploration

Write in front

npm has been used for so long, but I haven't explored it. Today, I'll explore it

reference material

http://nodejs.cn/learn/the-package-json-guide

Main article

file structure

For applications, package There are no fixed requirements for the content in the JSON file. The only requirement is that the JSON format must be followed, otherwise the program trying to access its properties programmatically cannot read it.
To put it bluntly, as long as it conforms to json format
The file can be generated automatically by using the command npm init, and of course, it can also be modified manually

name

{
   "name": "test-project"
}

The name of the package
The name must be less than 214 characters and cannot contain spaces. It can only contain lowercase letters, hyphens (-), or underscores ().

author

{
   "author": "Yoshino"
},

It can also be so

{
  "author": {
    "name": "Yoshino",
    "email": "",
    "url": "http://harekaze-misakiakeno.github.io/"
  }
}

The author name of the package

contributors

In addition to the author, the project can have one or more contributors. This property is an array that lists them

{
   "contributors": [
     "Akeno"
     ]
},

bugs

Link to the problem tracker of the software package. The most commonly used is the issues page of GitHub

{
   "bugs": "http://harekaze-misakiakeno.github.io/"
},

To be honest, I don't understand this place. What he means may be to read the configuration file after mining and give feedback? I don't know if there is a big man who understands it

homepage

Set the home page of the package

{
   "homepage": "http://harekaze-misakiakeno.github.io/"
},

version

Specifies the current version of the package

{
   "version": "0.0.1"
},

The first number is the major version number, the second number is the minor version number, and the third number is the patch version number.

The meaning of these numbers is: the version that only fixes defects is the patch version, the version that introduces backward compatible changes is the secondary version, and the major version has significant changes.

license

Specifies the license for the package

{
   "license": "MIT"
},

keywords

{
	"keywords": [
	  "hun",
	  "xian yu",
	  "la ji",
	  "mei qian tu",
	  "kan bu dao xi wang"
	]
}

This property contains an array of keywords related to package features
Browsing https://www.npmjs.com/ The website quickly sees the key words of the package in order to find your package

description

This property contains a brief description of the package
This attribute is particularly useful if you want to publish a package to npm, and one can know what the package is for.

  "description":  "understand package.json"

repository

This property specifies the location of this package repository
Here is the link of nodejs Chinese website

{
	"repository": "github:nodejscn/node-api-cn"
}

Or so

{
"repository": {
  "type": "git",
  "url": "https://github.com/nodejscn/node-api-cn.git"
  }
}

main

Set the entry point of the package.
When importing this package in the application, the application will search for the export of the module in this location.

{
  "main": "src/main.js"
}

private

If set to true, the application / package can be prevented from being accidentally published to npm

{
  "private": true
}

scripts

You can define a set of node scripts that can be run

{
"scripts": {
  "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
  "start": "npm run dev",
  "unit": "jest --config test/unit/jest.conf.js --coverage",
  "test": "npm run unit",
  "lint": "eslint --ext .js,.vue src test/unit",
  "build": "node build/build.js"
  }
}

These scripts are command line applications. You can run them by calling npm run XXXX or yarn XXXX, where XXXX is the name of the command. For example: npm run dev
You can use any name for a command, and a script can be any action
So when you enter npm run dev, a lot of operations are actually done behind it

dependencies

Set the list of npm packages installed as dependencies.

When installing packages using npm or yarn:

npm install <PACKAGENAME>
yarn add <PACKAGENAME>

The package is automatically inserted into this list.

Example:

{
"dependencies": {
  "vue": "^2.5.2"
}
}

devDependencies

Set the list of npm packages installed as development dependencies.

They are different from dependencies because they only need to be installed on the development machine and do not need to run code in the production environment.

When installing packages using npm or yarn:

npm install --dev <PACKAGENAME>
yarn add --dev <PACKAGENAME>

The package is automatically inserted into this list.

Example:

{
"devDependencies": {
  "autoprefixer": "^7.1.2",
  "babel-core": "^6.22.1"
}
}

engines

Set the node to run for this package / application JS or other command versions

{
"engines": {
  "node": ">= 10.0.0",
  "npm": ">= 10.0.0",
  "yarn": "^0.13.0"
}
}

However, it seems that changing npm to > = 10.0.0 does not affect the operation. I don't know why

browserslist

Used to tell which browsers (and their versions) to support. Babel, Autoprefixer, and other tools will use it to add the required polyfill and fallback to the target browser

"browserslist": [
  "> 1%",
  "last 2 versions",
  "not ie <= 8"
]

https://github.com/browserslist/browserslist

Tags: Javascript Front-end

Posted by shahansudu on Wed, 11 May 2022 06:18:16 +0300