疫情期間不得已要啓用遠程辦公,公司的 windows 遠程桌面有內網 npm 但沒法鏈接外網,環境配置起來很是難受。在配置 node-gyp 的時候花了很多時間,並且網上沒有一個清晰的教程,這裏整理一下。node
僅針對 windows 環境,但其餘環境也是相似的。git
首先不建議使用 windows-build-tools 這個包。我使用時遇到了幾個問題,並且在沒網絡的環境下,操做也並無簡化不少。反而是 node-gyp 說明裏介紹的手動安裝更加快捷。github
windows 下依賴就兩個,Visual Studio Build Tools 和 Python 。Python 版本 node-gyp 要求 2.7/3.5/3.6/3.7 均可以,保險起見建議裝 2.7 。npm
網上主要推薦的是 201五、2017 版本的 Build Tools ,但 2019 版本其實包含了前面的內容,node-gyp 說明裏讓下載的也是最新的 2019 版。windows
vs_buildtools.exe --layout C:\Users\<你的用戶名>\Desktop\BuildTooloffline\cache --add Microsoft.VisualStudio.Workload.VCTools
npm config set msvs_version 2017
https://nodejs.org/download/release/v12.14.1/node-v12.14.1-headers.tar.gz緩存
https://nodejs.org/download/release/v12.14.1/win-x64/node.libbash
headers.tar.gz
node.lib
複製到 Release 文件夾中。npm config set nodedir <include 和 Release 的父文件夾的路徑>
如今就能在離線機器上正常使用 node-gyp 了。網絡