什么是npm package
官網地址:https://docs.npmjs.com/cli/install
npm install的行為:
This command installs a package, and any packages that it depends on. If the package has a package-lock or shrinkwrap file, the installation of dependencies will be driven by that, with an npm-shrinkwrap.json taking precedence if both files exist. See package-lock.json and npm-shrinkwrap.
一個被安裝包如果有依賴,其依賴也會自動被安裝。
包的含義:
A package is:
a) a folder containing a program described by a package.json file
b) a gzipped tarball containing (a)
c) a url that resolves to (b)
d) a @ that is published on the registry (see npm-registry) with ?
e) a @ (see npm-dist-tag) that points to (d)
f) a that has a “latest” tag satisfying (e)
g) a that resolves to (a)
npm install執行的邏輯:
a. load the existing node_modules tree from disk
b. clone the tree
c. fetch the package.json and assorted metadata and add it to the clone
d. walk the clone and add any missing dependencies
dependencies will be added as close to the top as is possible without breaking any other modules
e. compare the original tree with the cloned tree and make a list of
f. actions to take to convert one to the other
g. execute all of the actions, deepest first
kinds of actions are install, update, remove and move
一個 SAP Spartacus 項目的package.json 例子:
{"name": "e2","version": "0.0.0","scripts": {"ng": "ng","start": "ng serve","build": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build","test": "ng test","lint": "ng lint","e2e": "ng e2e","prettier": "prettier --config ./.prettierrc --list-different \"projects/**/*{.ts,.scss,.html}\"","build:wtcmy:ssr": "ng build wtcmy --prod && ng run wtcmy:server:production","build:wtcph:ssr": "ng build wtcph --prod && ng run wtcph:server:production","build:wtcth:ssr": "ng build wtcth --prod && ng run wtcth:server:production","build:wtcid:ssr": "ng build wtcid --prod && ng run wtcid:server:production","build:wtcmy:ssr:production": "ng build wtcmy --prod && ng run wtcmy:server:production && mkdir -p ./projects/wtc/wtcmy/dist && mv ./projects/wtc/dist/wtcmy/server/main.js ./projects/wtc/wtcmy/dist/server.js && mv ./projects/wtc/dist/wtcmy ./projects/wtc/wtcmy/dist/wtcmy","build:wtcph:ssr:production": "ng build wtcph --prod && ng run wtcph:server:production && mkdir -p ./projects/wtc/wtcph/dist && mv ./projects/wtc/dist/wtcph/server/main.js ./projects/wtc/wtcph/dist/server.js && mv ./projects/wtc/dist/wtcph ./projects/wtc/wtcph/dist/wtcph","build:wtcth:ssr:production": "ng build wtcth --prod && ng run wtcth:server:production && mkdir -p ./projects/wtc/wtcth/dist && mv ./projects/wtc/dist/wtcth/server/main.js ./projects/wtc/wtcth/dist/server.js && mv ./projects/wtc/dist/wtcth ./projects/wtc/wtcth/dist/wtcth","build:wtcid:ssr:production": "ng build wtcid --prod && ng run wtcid:server:production && mkdir -p ./projects/wtc/wtcid/dist && mv ./projects/wtc/dist/wtcid/server/main.js ./projects/wtc/wtcid/dist/server.js && mv ./projects/wtc/dist/wtcid ./projects/wtc/wtcid/dist/wtcid","build:ssr": "ng build e2-lib --prod && yarn build:wtcmy:ssr:production && yarn build:wtcph:ssr:production && yarn build:wtcth:ssr:production && yarn build:wtcid:ssr:production","serve:wtcmy:ssr": "node projects/wtc/dist/wtcmy/server/main.js","serve:wtcph:ssr": "node projects/wtc/dist/wtcph/server/main.js","serve:wtcth:ssr": "node projects/wtc/dist/wtcth/server/main.js","serve:wtcid:ssr": "node projects/wtc/dist/wtcid/server/main.js","build:client-and-server-bundles": "ng build wtcmy --prod && ng run wtcmy:server","webpack:server": "webpack --config projects/wtc/webpack.server.config.js --progress --colors"},"schematics": "./projects/e2-spartacus-schematics/src/collection.json","private": true,"dependencies": {"@angular-slider/ngx-slider": "^2.0.3","@angular/animations": "9.1.9","@angular/common": "9.1.9","@angular/compiler": "9.1.9","@angular/core": "9.1.9","@angular/forms": "9.1.9","@angular/localize": "9.1.9","@angular/platform-browser": "9.1.9","@angular/platform-browser-dynamic": "9.1.9","@angular/platform-server": "9.1.9","@angular/router": "9.1.9","@angular/service-worker": "9.1.9","@ng-bootstrap/ng-bootstrap": "^6.1.0","@ng-select/ng-select": "^4.0.0","@ngrx/effects": "~9.1.0","@ngrx/router-store": "~9.1.0","@ngrx/store": "^9.1.0","@ngrx/store-devtools": "^9.1.0","@nguniversal/express-engine": "^9.1.0","@nguniversal/module-map-ngfactory-loader": "^8.1.1","@spartacus/core": "2.0.0","@spartacus/storefront": "2.0.0","@types/googlemaps": "^3.39.3","@types/swiper": "^5.2.0","bootstrap": "^4.4.1","cheerio": "^1.0.0-rc.6","core-js": "^2.5.4","deepmerge": "^4.2.2","express": "^4.15.2","helmet": "^4.2.0","i18next": "^19.4.5","i18next-xhr-backend": "^2.0.1","js-sha256": "^0.9.0","moment": "2.27.0","ng2-ion-range-slider": "^2.0.0","ngx-cookie-service": "10.1.1","ngx-infinite-scroll": "^8.0.1","ngx-moment": "^3.5.0","ngx-red-zoom": "^0.2.1","ngx-script-loader": "^1.3.0","rxjs": "^6.4.0","swiper": "^5.3.1","ts-md5": "^1.2.7","tslib": "^1.10.0","zone.js": "~0.10.2"},"devDependencies": {"@angular-devkit/build-angular": "~0.901.4","@angular-devkit/build-ng-packagr": "~0.901.4","@angular/cli": "^9.1.4","@angular/compiler-cli": "9.1.4","@angular/language-service": "~9.1.0","@ngrx/schematics": "^8.1.0","@types/express": "^4.17.7","@types/jasmine": "~2.8.8","@types/jasminewd2": "~2.0.3","@types/node": "^12.11.1","codelyzer": "^5.1.2","jasmine-core": "^3.5.0","jasmine-spec-reporter": "~4.2.1","karma": "^4.4.1","karma-chrome-launcher": "~2.2.0","karma-coverage-istanbul-reporter": "~2.0.1","karma-jasmine": "^3.1.1","karma-jasmine-html-reporter": "^1.5.2","ng-packagr": "^9.0.0","prettier": "^1.18.2","protractor": "~5.4.0","ts-loader": "^5.3.2","ts-node": "~7.0.0","tslint": "~5.11.0","typescript": "3.8.3","webpack-cli": "^3.3.2"} }總結
以上是生活随笔為你收集整理的什么是npm package的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华为 P20 等 13 款设备启动鸿蒙
- 下一篇: 没有二代接班 俞敏洪称可以考虑董宇辉接班