An warware: cire abubuwan dogaro daga node_modules

Node da manajan kunshin sa, npm, kayan aiki ne masu mahimmanci don haษ“aka aikace-aikacen JavaScript na zamani. A lokaci guda, sarrafa fakitin Node na iya zama ษ—an gajiyar wasu lokuta. Wani takamaiman batun masu haษ“akawa galibi ke fuskanta shine sarrafa abubuwan dogaro a cikin babban fayil ษ—in node_modules. Waษ—annan abubuwan dogaro na iya zama babba, kuma ba a amfani da su a cikin lambar samarwa. Don haka, al'ada ce ta gama gari don cire waษ—annan yayin gini don samarwa. A cikin wannan labarin, za mu bincika yadda ake cire abubuwan dogaro daga babban fayil ษ—in node_modules.

Fahimtar Dev Dependencies

Dev Dependencies VS Abubuwan Dogara

A cikin JavaScript, akwai bambanci tsakanin dev dependencies, waษ—anda ake buฦ™ata yayin haษ“akawa da gwaji, da dogaro da samarwa, waษ—anda ake buฦ™ata don gudanar da aikace-aikacen.

{
  "name": "sample_project",
  "version": "1.0.0",
  "devDependencies": {
    "jest": "^26.6.3",
    "eslint": "^7.22.0"
  },
  "dependencies": {
    "express": "^4.17.1",
    "mongoose": "^5.12.1"
  }
}

Aiki tare da node_modules

Babban fayil ษ—in node_modules shine inda Node ke kiyaye duk abin dogaro na aikin ku. Amma yana iya yin cunkoson jama'a, musamman tare da dogaro da dev waษ—anda ba a buฦ™ata don sigar samarwa na aikace-aikacenku.

Cire Dev Dependencies

npm prune - samarwa

Hanya mafi sauฦ™i don cire abubuwan dogara daga node_modules directory shine amfani da umarnin npm 'npm prune โ€“production'. Wannan umarnin yana cire fakitin da ba a buฦ™ata don samarwa, yana barin ku da slimmer node_modules.

$ npm prune --production

Fahimtar umarnin npm prune

Umurnin prune na npm yana cire fakitin "m". Fakitin na ban sha'awa fakiti ne waษ—anda ba a jera su a jerin abubuwan dogaro da fakitin iyaye ba. Lokacin da aka ฦ™ara tutar -production, umarnin kuma yana cire fakitin da aka jera a cikin devDependencies.

Bayanin Bayanin Mataki-mataki

Mataki 1: Bincika fayil ษ—in kunshin.json ษ—inku don tabbatar da cewa kun rarraba abubuwan dogaronku daidai da 'dogara' da 'Dependencies'.

Mataki 2: Gudun umarnin 'npm prune-production'. Wannan zai cire devDependencies daga babban fayil ษ—in node_modules.

$ npm prune --production

Mataki 3: Yanzu, babban fayil ษ—in node_modules ya ฦ™unshi fakitin da aka jera a cikin 'dogara' a cikin fayil ษ—in ku na kunshin.json.

Wannan tsari yana rage girman girman babban fayil ษ—in node_modules kuma ana amfani dashi sosai kafin tura aikace-aikacenku don samarwa.

Ka tuna, mabuษ—in sarrafa node_modules shine fahimtar bambanci tsakanin abubuwan dogaro da abubuwan samarwa, da umarnin npm waษ—anda ke taimaka mana sarrafa su. Kuma 'npm prune -production' ษ—aya ne irin wannan umarni mai amfani wanda ke taimakawa wajen haษ“aka babban fayil ษ—in node_modules ta hanyar cire abubuwan dogaro da ba dole ba.

lura: Dole ne a yi amfani da umarnin 'npm prune -production' a hankali kuma kawai lokacin da kuka tabbatar game da fakitin cikin abubuwan dogaro. Wannan saboda da zarar an datse, waษ—annan fakitin za su buฦ™aci a sake shigar da su don haษ“akawa.

Shafi posts:

Leave a Comment