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.