如何在JSX中使用nodemon?

mpe*_*pen 8 node.js reactjs nodemon react-jsx

我可以用一个命令编译和运行我的JSX应用程序:

jsx app.jsx | node
Run Code Online (Sandbox Code Playgroud)

但我也希望我的服务器每次修改时都会自动重启app.jsx.我可以用nodemon做到这一点,但我无法弄清楚如何让nodemon事先通过JSX编译器运行我的脚本.

我有一个这样的nodemon.json文件设置:

{
    "execMap": {
        "js": "node",
        "jsx": "jsx {{filename}} | node"
    },
    "ext": "js jsx",
    "ignore": [
        ".hg",
        "node_modules",
        ".idea"
    ],
    "verbose": true
}
Run Code Online (Sandbox Code Playgroud)

但是当我跑的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.
Run Code Online (Sandbox Code Playgroud)

这很奇怪,因为当我将它直接粘贴到终端时,该命令会逐字逐句.

有没有办法让nodemon运行我的JSX文件?

Bri*_*and 5

似乎nodemon正在尝试使用您提供的名称运行程序,而不是执行shell.

使用此内容创建一个jsx.sh文件:

#!/bin/sh
jsx "$1" | node
Run Code Online (Sandbox Code Playgroud)

然后chmod +x jsx.sh,将它放在你的nodemon.json中:

{
    "execMap": {
        "js": "node",
        "jsx": "./jsx.sh"
    },
    "ext": "js jsx",
    "ignore": [
        ".hg",
        "node_modules",
        ".idea"
    ],
    "verbose": true
}
Run Code Online (Sandbox Code Playgroud)

*未经测试