Angular and NPM dependencies VS devDependencies

丶灬走出姿态 提交于 2020-03-23 07:34:25

问题


after un bunch of reading on this matter and following this very usefull post : What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?

I know that dependencies should reference every runtime libs and devDependencies references every usefull for development dependencies.

But I am now confused. For production usage, I will have to ng build --production my Angular app. If I do npm install --production, I can't even compile with ng build --production. I need to npm install and get every devDependencies installed. Knowing that, I tried to put everything under devDependencies, And then I did a ng build --prod, the resulting [dist] folder has everything needed, and can be served as a full angular app.

So, 1st question is : Appart from make an "on paper" difference between runtime libs and dev libs, why should I use dependencies ?

Other question: To avoid vulnerabilities on dependencies of dependencies I can force the usage of a specific version by putting this lib in the package.json (as long as the major version is the same). But I would like to avoid putting this lib in the dependencies or devDependencies, should I put this lib under peerDependencies ? optionnalDependencies ? bundledDependencies ?

Thanks for any inputs on this.

EDIT

Example package.json has been required:

{
  "name": "ANGULAR_PROJECT",
  "version": "X.Y.Z",
  "repository": {
    "type": "git",
    "url": "A_GIT_URL"
  },
  "scripts": {
    "ng": "ng",
    "test": "ng test",
    "e2e": "protractor e2e/conf/protractor.conf.js",
    "e2e:dev": "protractor e2e/conf/protractor-dev.conf.js",
  },
  "private": true,
  "dependencies": {
  },
  "devDependencies": {
    "@angular/pwa": "^0.12.4",
    "@angular/animations": "^8.2.11",
    "@angular/cdk": "^8.2.3",
    "@angular/common": "^8.2.11",
    "@angular/compiler": "^8.2.11",
    "@angular/core": "^8.2.11",
    "@angular/forms": "^8.2.11",
    "@angular/material": "^8.2.3",
    "@angular/material-moment-adapter": "^8.2.3",
    "@angular/platform-browser": "^8.2.11",
    "@angular/platform-browser-dynamic": "^8.2.11",
    "@angular/platform-server": "^8.2.11",
    "@angular/router": "^8.2.11",
    "@angular/service-worker": "^8.2.11",
    "@mat-datetimepicker/core": "^2.0.1",
    "@mat-datetimepicker/moment": "^2.0.1",
    "@ngrx/effects": "8.4.0",
    "@ngrx/router-store": "8.4.0",
    "@ngrx/schematics": "8.4.0",
    "@ngrx/store": "8.4.0",
    "@ngrx/store-devtools": "8.4.0",
    "@swimlane/ngx-charts": "12.0.1",
    "angular-gridster2": "^8.2.0",
    "angular-particle": "^1.0.4",
    "array-flat-polyfill": "^1.0.1",
    "apollo-angular": "^1.8.0",
    "apollo-angular-link-http": "^1.9.0",
    "apollo-cache-inmemory": "^1.6.3",
    "apollo-client": "^2.6.4",
    "apollo-link": "^1.2.13",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.5.4",
    "graphql": "14.0.0",
    "graphql-tag": "^2.10.1",
    "hammerjs": "^2.0.8",
    "json-server": "^0.14.2",
    "jsonpath": "^1.0.2",
    "moment": "^2.22.2",
    "ngrx-store-freeze": "^0.2.4",
    "ngrx-store-localstorage": "^8.0.0",
    "ngx-cacheable": "^1.2.5",
    "ngx-parallax": "^4.0.0",
    "node-sass": "4.13.1",
    "rxjs": "^6.5.3",
    "web-animations-js": "^2.3.2-pr208",
    "xlsx": "^0.14.2",
    "zone.js": "~0.9.1",
    ----------------------------------------------- REAL DEV DEPENDENCIES UNDER
    "@angular-devkit/build-angular": "^0.803.10",
    "@angular/cli": "^8.3.10",
    "@angular/compiler-cli": "^8.2.11",
    "@angular/language-service": "^8.2.11",
    "@commitlint/cli": "^7.2.1",
    "@types/chai": "^4.2.6",
    "@types/cucumber": "^6.0.0",
    "@types/jasmine": "~3.4.6",
    "@types/jasminewd2": "~2.0.8",
    "@types/node": "~8.9.4",
    "chai": "^4.2.0",
    "codelyzer": "~5.2.0",
    "commitizen": "^4.0.3",
    "conventional-changelog-cli": "^2.0.1",
    "cucumber": "5.1.0",
    "cucumber-html-reporter": "^5.0.2",
    "cz-customizable": "^5.3.0",
    "cz-customizable-ghooks": "^1.5.0",
    "husky": "^4.2.1",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.4.1",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "karma-sonarqube-reporter": "^1.2.5",
    "karma-sonarqube-unit-reporter": "^0.0.21",
    "karma-spec-reporter": "0.0.32",
    "lint-staged": "^8.1.0",
    "mkdirp": "^0.5.1",
    "ng-mocks": "^8.1.0",
    "prettier": "^1.15.3",
    "protractor": "5.4.2",
    "protractor-cucumber-framework": "^6.2.0",
    "rxjs-compat": "^6.3.3",
    "ts-comparators": "^1.0.0",
    "ts-mockery": "1.2.0",
    "ts-node": "~7.0.1",
    "tslint": "~5.11.0",
    "tslint-config-prettier": "^1.18.0",
    "tslint-plugin-prettier": "^2.0.1",
    "typescript": "^3.1.6"
  },
  "peerDependencies": {

  }
}

来源:https://stackoverflow.com/questions/60502489/angular-and-npm-dependencies-vs-devdependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!