如何在 JSX 中使用 nodemon?
How to use nodemon with JSX?
我可以用一个命令编译和 运行 我的 JSX 应用程序:
jsx app.jsx | node
但是我也希望我的服务器每次修改后自动重启app.jsx
。我可以用 nodemon 做到这一点,但我不太清楚如何事先通过 JSX 编译器让 nodemon 到 运行 我的脚本。
我有一个 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 "" | node
然后 chmod +x jsx.sh
,然后将其放入您的 nodemon.json:
{
"execMap": {
"js": "node",
"jsx": "./jsx.sh"
},
"ext": "js jsx",
"ignore": [
".hg",
"node_modules",
".idea"
],
"verbose": true
}
* 未测试
如果您在 Windows(像我一样),您可以创建 .bat
而不是像
这样的 .sh
@echo off
jsx %1 | node
此文件必须与 nodemon.json
和 package.json
位于同一目录中 -- 由于某种原因,路径似乎在 execMap
中不起作用。
此外,一个更简单的解决方案是 不 在 main/server 脚本中使用任何 JSX,安装 node-jsx 然后 require
根据需要你的 JSX 文件。
或者您可以在 ./node_modules/.bin
目录中找到 jsx 命令,然后 运行 将其关闭:
{
script: "client.js",
options: {
execMap: {
"js": "node",
"jsx": "./node_modules/.bin/jsx \"\" | node"
},
ext: "js jsx",
callback: function (nodemon) {
nodemon.on("log", function (event) {
console.log(event.colour);
});
},
ignore: [
"node_modules/**/*.js",
"public/js/**",
"lib/api/**",
]
}
}
我可以用一个命令编译和 运行 我的 JSX 应用程序:
jsx app.jsx | node
但是我也希望我的服务器每次修改后自动重启app.jsx
。我可以用 nodemon 做到这一点,但我不太清楚如何事先通过 JSX 编译器让 nodemon 到 运行 我的脚本。
我有一个 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 "" | node
然后 chmod +x jsx.sh
,然后将其放入您的 nodemon.json:
{
"execMap": {
"js": "node",
"jsx": "./jsx.sh"
},
"ext": "js jsx",
"ignore": [
".hg",
"node_modules",
".idea"
],
"verbose": true
}
* 未测试
如果您在 Windows(像我一样),您可以创建 .bat
而不是像
.sh
@echo off
jsx %1 | node
此文件必须与 nodemon.json
和 package.json
位于同一目录中 -- 由于某种原因,路径似乎在 execMap
中不起作用。
此外,一个更简单的解决方案是 不 在 main/server 脚本中使用任何 JSX,安装 node-jsx 然后 require
根据需要你的 JSX 文件。
或者您可以在 ./node_modules/.bin
目录中找到 jsx 命令,然后 运行 将其关闭:
{
script: "client.js",
options: {
execMap: {
"js": "node",
"jsx": "./node_modules/.bin/jsx \"\" | node"
},
ext: "js jsx",
callback: function (nodemon) {
nodemon.on("log", function (event) {
console.log(event.colour);
});
},
ignore: [
"node_modules/**/*.js",
"public/js/**",
"lib/api/**",
]
}
}