如何在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.

这很奇怪,因为当我直接将其粘贴到终端中时,该命令会逐字运行。

有什么办法让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
}

*未测试

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章