An warware: babban fayil ɗin node_modules mai tsabta na npm

Npm da kuma node_modules taka muhimmiyar rawa a cikin yanayin ci gaban JavaScript na zamani. Suna girka da sarrafa duk abubuwan dogaro da ake buƙata don aikin ku, suna sauƙaƙe rabawa da rarraba lambar ku. Koyaya, babban fayil ɗin node_modules na iya zama kumbura tare da fakitin da ba dole ba, yana rage jinkirin tsarin ci gaban ku. Wannan labarin zai rufe hanya don tsaftace babban fayil ɗin node_modules da aka shigar cikin npm yadda ya kamata da inganci.

Ɗayan maganin wannan matsala shine amfani npm ci. Wannan umarnin yana cire babban fayil ɗin node_modules kuma yana sake shigar da duk abin dogaro daga karce. Zai duba kunshin ku-lock.json kawai, yin watsi da kunshin.json idan akwai rashin daidaituwa, yana tabbatar da ainihin abin dogaro iri ɗaya kowane lokaci.

npm ci

Bayanin Mataki-Ta-Taki na Code

Bari mu zurfafa zurfafa cikin ayyukan npm ci. Lokacin da kuke gudanar da wannan umarni, NPM zai yi masu zuwa:

  • Share babban fayil ɗin node_modules na yanzu.
  • Dauki duk abubuwan dogaro da aka kayyade a cikin fayil ɗin ku-lock.json daga rijistar npm.
  • Shigar da haɗa duk abin dogara.

Sakamakon shine sabon shigar da duk abin dogara ba tare da ragi na fakitin sun toshe babban fayil ɗin node_modules ba.

Matsayin kunshin-lock.json

Don fahimtar yadda npm ci yana aiki, yana da mahimmanci a fahimci rawar kunshin-lock.json fayil. Wannan fayil ɗin yana ɗaukar ainihin bishiyar dogaro a wani wuri da aka ba. Don haka, lokacin da npm ci ya sake shigar da abin dogaro, yana amfani da nau'ikan da aka kama a cikin fayil ɗin kunshin-lock.json, yana tabbatar da shigarwar ya daidaita duk lokacin da aka gudanar.

Ingantaccen npm ci

Ingancin npm ci ya fito ne daga ikonsa na ketare ƙudurin sigar fakitin mutum ɗaya. Madadin haka, yana amfani da pack-lock.json don shigar da ainihin nau'ikan ba tare da buƙatar ƙuduri ba. Wannan yana haifar da shigarwa mai sauri da tsafta fiye da shigar da tsoho na npm.

Yana da mahimmanci a lura cewa umarnin npm ci yana da amfani musamman a cikin ci gaba da yanayin haɗin kai, inda kake son tabbatar da littafin node_modules yana cikin yanayi mai tsabta don kowane gini.

Ƙarin ɗakunan karatu da Ayyuka

Yayin da npm ci kayan aiki ne mai ƙarfi, akwai kuma sauran ɗakunan karatu da ayyuka waɗanda aikinku zai iya amfana da su. npm zuw, alal misali, yana cire fakitin "m". Kunshin na waje shine wanda ba a jera shi akan jerin abubuwan dogaro da fakitin iyaye ba.

npm prune

Bayan gudanar da wannan umarni, fakitin da ya kamata su kasance a cikin babban fayil ɗin node_modules kawai sun rage. Bugu da ƙari, akwai dakunan karatu kamar depcheck wanda zai bincika lambar ku kuma ya gaya muku fakitin da ba ku amfani da su, wanda za ku iya yanke shawarar cirewa da hannu.

A ƙarshe, sarrafa node_modules da kiyaye shi mai tsabta yana da mahimmanci ga ingantaccen yanayin ci gaban JavaScript. Koyon abubuwan da ke faruwa na npm da yin amfani da ƙaƙƙarfan tsarin fasali da umarni zasu taimaka samun mafi kyawun aikinku.

Shafi posts:

Leave a Comment