[英]Nodemon start script and running eslint
I'm starting a project in Vue.JS and I'm a little new to nodemon.我正在 Vue.JS 中开始一个项目,我对 nodemon 有点陌生。
Here is my package.json file这是我的 package.json 文件
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon src/app.js --exec 'npm run eslint'",
"lint": "eslint **/*.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"eslint": "^4.16.0",
"nodemon": "^1.14.12"
}
}
I can get nodemon to run through app.js with "nodemon src/app.js".我可以使用“nodemon src/app.js”让 nodemon 通过 app.js 运行。 I've tried a whole bunch of combinations after --exec and haven't had any luck.
我在 --exec 之后尝试了一大堆组合,但没有任何运气。
The correct way is (in package.json and windows):正确的方法是(在 package.json 和 windows 中):
"scripts": {
"start": "node index",
"start-dev": "nodemon --exec \"npm run lint && node index\"",
},
This works pretty fine for your use-case.这对您的用例非常有效。
nodemon src/app.js --exec "npm run lint && node"
or you can write nodemon.json file in your root directory或者您可以在根目录中写入 nodemon.json 文件
{
"watch": ["src"],
"ignore": ["**/*.test.js", "**/*.spec.js", ".git", "node_modules"],
"exec": "npm run lint && node src/app.js"
}
I've been using a custom script for a while now which I finally published to npm.我已经使用自定义脚本一段时间了,我最终将其发布到 npm。 Check it out here: https://github.com/theoephraim/lint-fix-nodemon
在这里查看: https : //github.com/theoephraim/lint-fix-nodemon
This helps avoid double restarts when eslint fixes your files as well as not failing on the initial run if eslint has fatal errors.这有助于避免 eslint 修复文件时的双重重启,以及如果 eslint 出现致命错误,则不会在初始运行时失败。
Hope it helps!希望有帮助!
Im using nodemon
version 1.19.4.我使用
nodemon
版本 1.19.4。 You just missed the "events" key.您只是错过了“事件”键。 The right way would be to create a
nodemon.json
in your root folder like that, then a lint
script in your package.json
with your lint
command:正确的方法是在您的根文件夹中创建一个
nodemon.json
,然后使用您的lint
命令在您的package.json
创建一个lint
脚本:
{
"watch": [ "src" ],
"ignore": ["**/*.test.js", "**/*.spec.js", ".git", "node_modules"],
"events": {
"restart": "npm run lint"
}
}
Here you can check about Nodemon Events. 在这里您可以查看 Nodemon 事件。
When using events you don't need to manually handle your application state (restart, crash, node execution, etc), just put what you want to happen when nodemon
refreshes.使用事件时,您不需要手动处理应用程序状态(重启、崩溃、节点执行等),只需在
nodemon
刷新时放置您想要发生的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.