Windows 10 下安裝 npm 後全域 node_modules 和 npm-cache 檔案夾的設定

來源:互聯網
上載者:User

標籤:

npm 指 Node Package Manager,是 Node.js 中一個流行的包管理和分發工具。Node.js 在某個版本的 Windows 安裝包開始已經加入了 npm,現在可以進入 https://nodejs.org/en/ 下載安裝包。

安裝過程很簡單,一路 Next 然後 Finish 就好。安裝完成後可以建立一個命令列視窗,敲 npm 驗證安裝。

我碰到的問題是,當我安裝完一個全域的 webpack 工具後,發現很多新下載的檔案分別存到了 %appdata% 下的 node_modules 和 npm-cache 這兩個檔案夾中,我不爽是因為 %appdata% 是 Roaming 的,這些東西其實並不需要 roam。

npm 的文檔 https://docs.npmjs.com/files/folders 說了一堆,並沒什麼用,最後我在爆棧的這個回答的啟發下找到了適合我的方法:

npm config set prefix ${userprofile}\.npm --globalnpm config set cache ${userprofile}\.npm\cache --global

這樣一來,會有一個 npmrc 檔案產生在 %appdata%\npm\etc 檔案夾中,內容就是上面的配置,這個設定檔 roam 是沒問題的。

Windows 10 下安裝 npm 後全域 node_modules 和 npm-cache 檔案夾的設定

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.