我認爲npm install|update
需要依賴源文件,但當我想運行一個可執行文件,如nodemon
,它似乎不工作。它試圖在全球範圍內尋找文件嗎?我怎樣才能讓這些命令先看看node_modules
?NPM package.json依賴關係及其在本地和全局的可執行文件
我有一個Cakefile,用nodemon
啓動dev服務器。例如:
# **`procExec(procName)`**
# returns the path to executable in `node_`
procExec = (procName) ->
console.log "./node_modules/" + procName + "/bin/" + procName
"./node_modules/.bin/" + procName
# **`cake startdev`**
# Starts the server with `nodemon`
# Watch and compile `.coffee` and `.styl` files in `/client`
task "startdev", "Starts server with nodemon and watch files for changes", ->
# start nodemon server
nodemon = spawn procExec("nodemon"), ["server.coffee"]
processOutput nodemon
# watch and compile CoffeeScript
coffee = spawn procExec("coffee"), ["-o", "public/js/app", "-cw", "client/coffee"]
processOutput coffee
# watch and compile Stylus
stylus = spawn procExec("stylus"), ["client/stylus", "-l", "-w", "-o", "public/css/app"]
processOutput stylus
它的工作原理,但有一些小問題:
npm install|update
似乎沒有安裝nodemon
。我認爲它試圖在全球安裝並失敗。我手動單獨做了npm install nodemon
。爲什麼是這樣?我怎麼能告訴nodemon
無論如何安裝?"./node_modules/.bin/" + procName
是否總是解析爲正確的可執行文件?
Wheres the'npm = require ...'中的代碼是產生該過程的答案的一部分嗎? – 2012-08-20 07:03:03
對不起,我沒有看到這一段時間。你仍然會像以前一樣使用'spawn',但沒有procExec幫助器。 – grncdr 2012-08-28 00:28:02