What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?

前端 未结 14 1750
灰色年华
灰色年华 2020-11-22 00:43

This documentation answers my question very poorly. I didn\'t understand those explanations. Can someone say in simpler words? Maybe with examples if it\'s hard to choose si

14条回答
  •  北海茫月
    2020-11-22 01:35

    Dependencies

    These are the packages that your package needs to run, so they will be installed when people run

     npm install PACKAGE-NAME
    

    An example would be if you used jquery in your project. If someone doesn't have jquery installed, then it wouldn't work. To save as a dependancy, use

     npm install --save
    

    Dev-Dependancies

    These are the dependancies that you use in development, but isn't needed when people are using it, so when people run npm install, it won't install them since the are not necassary. For example, if you use mocha to test, people don't need mocha to run, so npm install doesn't install it. To save as a dev dependancy, use

    npm install PACKAGE --save-dev
    

    Peer Dependancies

    These can be used if you want to create and publish your own library so that it can be used as a dependency. For example, if you wan't your package to be used as a dependancy in another project, then these will also be installed when someone install's the project which has your project as a dependancy. Most of the time you won't use peer dependancies.

提交回复
热议问题