npm學習(十七)之node_modules中的bin文件夾


可執行文件

在本地模式下,可執行文件指向的位置;

  • ./node_modules/.bin 以便可以通過 npm 運行的腳本使用它們。

    • 例如,當您運行測試,將在路徑中 npm test

npm為script字段中的腳本路徑都加上了node_moudles/.bin前綴

npm為script字段中的腳本路徑都加上了node_moudles/.bin前綴,這意味着:你在試圖運行本地安裝的依賴在 node_modules/.bin 中的腳本的時候,可以省略node_modules/.bin這個前綴。例如:

我剛npm install webpack了,而在我的項目下的node_modules目錄的.bin子目錄下:

就多了一個叫做webpack的腳本

 

本來運行這個腳本的命令應該是:node_modules/.bin webpack

但由於npm已經自動幫我們加了node_modules/.bin前綴了,所以我們可以直接寫成:

"scripts": {"start": "webpack"}

而不用寫成:

"scripts": {"start": "node_modules/.bin webpack"}

原文:npm run adds node_modules/.bin to the PATH provided to scripts. Any binaries provided by locally-installed dependencies can be used without the node_modules/.bin prefix

總結

在本地環境下,可行性文件放在node_modules下的.bin文件夾中,npm為scripts字段中的腳本路徑自動添加了node_modules/.bin前綴,所以可以直接寫

"scripts": {"start": "webpack"}

而不是

"scripts": {"start": "node_modules/.bin webpack"}

參考

NPM node_modules 文檔夾的詳解

【npm】伙計,給我來一杯package.json!不加糖


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM