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

前端 未结 14 1756
灰色年华
灰色年华 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:20

    Dependencies vs dev dependencies

    Dev dependencies are modules which are only required during development whereas dependencies are required at runtime. If you are deploying your application, dependencies has to be installed, or else your app simply will not work. Libraries that you call from your code that enables the program to run can be considered as dependencies.

    Eg- React , React - dom

    Dev dependency modules need not be installed in the production server since you are not gonna develop in that machine .compilers that covert your code to javascript , test frameworks and document generators can be considered as dev-dependencies since they are only required during development .

    Eg- ESLint , Babel , webpack

    @FYI,

    mod-a
      dev-dependents:
        - mod-b
      dependents:
        - mod-c
    
    mod-d
      dev-dependents:
        - mod-e
      dependents:
        - mod-a
    
    ----
    
    npm install mod-d
    
    installed modules:
      - mod-d
      - mod-a
      - mod-c
    
    ----
    
    checkout the mod-d code repository
    
    npm install
    
    installed modules:
      - mod-a
      - mod-c
      - mod-e
    

    If you are publishing to npm, then it is important that you use the correct flag for the correct modules. If it is something that your npm module needs to function, then use the "--save" flag to save the module as a dependency. If it is something that your module doesn't need to function but it is needed for testing, then use the "--save-dev" flag.

    # For dependent modules
    npm install dependent-module --save
    
    # For dev-dependent modules
    npm install development-module --save-dev
    

提交回复
热议问题