[英]How to use nodemon with JSX?
我可以用一個命令編譯和運行我的JSX應用程序:
jsx app.jsx | node
但我也希望每次修改app.jsx
時我的服務器都會自動重啟。 我可以用nodemon做到這一點 ,但我無法弄清楚如何讓nodemon事先通過JSX編譯器運行我的腳本。
我有一個nodemon.json
文件設置如下:
{
"execMap": {
"js": "node",
"jsx": "jsx {{filename}} | node"
},
"ext": "js jsx",
"ignore": [
".hg",
"node_modules",
".idea"
],
"verbose": true
}
但是當我運行nodemon
它會告訴我:
8 Feb 21:58:48 - [nodemon] starting `jsx app.jsx | node`
8 Feb 21:58:48 - [nodemon] child pid: 10976
'\"jsx app.jsx | node\"' is not recognized as an internal or external command,
operable program or batch file.
這很奇怪,因為當我將它直接粘貼到終端時,該命令會逐字逐句。
有沒有辦法讓nodemon運行我的JSX文件?
似乎nodemon正在嘗試使用您提供的名稱運行程序,而不是執行shell。
使用此內容創建一個jsx.sh文件:
#!/bin/sh
jsx "$1" | node
然后chmod +x jsx.sh
,並把它放在你的nodemon.json中:
{
"execMap": {
"js": "node",
"jsx": "./jsx.sh"
},
"ext": "js jsx",
"ignore": [
".hg",
"node_modules",
".idea"
],
"verbose": true
}
*未經測試
或者您可以在./node_modules/.bin
目錄中找到jsx命令,然后將其運行:
{
script: "client.js",
options: {
execMap: {
"js": "node",
"jsx": "./node_modules/.bin/jsx \"$1\" | node"
},
ext: "js jsx",
callback: function (nodemon) {
nodemon.on("log", function (event) {
console.log(event.colour);
});
},
ignore: [
"node_modules/**/*.js",
"public/js/**",
"lib/api/**",
]
}
}
如果你在Windows上(像我一樣)你可以創建一個.bat
而不是.sh
像FakeRainBrig並建議
@echo off
jsx %1 | node
此文件必須與nodemon.json
和package.json
位於同一目錄中 - 無論出於何種原因,路徑似乎在execMap
中都execMap
。
此外,更簡單的解決方案是在主/服務器腳本中不使用任何JSX,安裝node-jsx ,然后根據require
JSX文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.