1
2
3"scripts": {
"build": "webpack"
},
npm 在執行 scripts 的時候,會將 node_modules/.bin 加入暫時性的 path,所以在執行 npm run build 得時候,等同於 npm run node_modules/.bin/webpack,如果沒有這個檔案的時候,才會執行 global webpack。
This works because npm adds node_modules/.bin temporarily to the path. As a result, rather than having to write “build”: “node_modules/.bin/webpack”, we can do just “build”: “webpack”. Unless Webpack is installed to the project, this can point to a possible global install. That can be potentially confusing. Prefer local installs over global for this reason.