NodeJs npm install package management tool, commonly used commands
package.json some entry
dependencies
Refers to the production
package needs to ambient
// 添加到您package.json的 dependencies:
`npm install <package_name> --save`
复制代码
devDependencies
Only development
and the testing
environment when required installation package
// 添加到您package.json的 devDependencies:
`npm install <package_name> --save-dev`
复制代码
optionalDependencies
If some package
can not be installed, but you still want to continue npm install, you can put these uncertain whether that can be installed package
into this below
But to ensure that the program still have to install thesepackage
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()
}
复制代码
Note: The optionalDependencies
configuration will be covered devDependencies
, usually the best option is to write in one place
npm install
Any package will install the package and its dependencies
npm install (无参数)
All modules will be installed as dependencies package.json
-D, --save-dev
Installation package will appear in devDependencies
-O, --save-optional
Installation package will appear in optionalDependencies
--no-save
Save to prevent dependencies
-P, --save-prod
Installation package will appear dependencies
, this is the default, unless -D
or-O
-g, --global
The global installation package installed
asl run
From package.json
the scripts
object to run arbitrary commands
// vue cli3 中的 package.json
// 执行 npm run serve
// 实际上是 npm run node_modules/.bin/vue-cli-service serve
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
}
复制代码
Reproduced in: https: //juejin.im/post/5cfe05d56fb9a07ee9586494