如何在JSX中使用nodemon?
我可以用一个命令编译和运行我的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.
这很奇怪,因为那个命令直接粘贴到我的terminal上时是可以正常使用的。
有没有什么方法可以让nodemon运行我的JSX文件?
看来nodemon试图用你提供的名字来运行一个程序,而不是执行一个shell。
用这个内容创build一个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 }
*未经testing
或者你可以在你的./node_modules/.bin
目录中findjsx命令,然后运行它:
{ 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上(像我一样),你可以创build一个.bat
而不是.sh
就像FakeRainBrigand
@echo off jsx %1 | node
这个文件必须与nodemon.json
和package.json
位于同一个目录中 – 无论出于何种原因,path在execMap
似乎都不起作用。
而且,更简单的解决scheme是在主/服务器脚本中不使用任何JSX,安装node-jsx ,然后根据require
安装JSX文件。