如何使用nodemon进行linting?

DrE*_*est 12 javascript node.js npm nodemon eslint

我可以使用nodemon来lint我的javascript吗?我没有使用任何构建工具,例如gulp或grunt,并且想要最大化节点和npm的使用.

nodemon的输出可以通过管道输出.我想使用它来使用eslint来修改已更改的文件.

这是我的package.json

{
  "name": "app",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "nodemon server.js",
    "lint": "eslint"
  },
  "dependencies": {
    "MD5": "*",
    "clean-css": "*",
    "express": "~4.9.0",
    "express-handlebars": "~2.0.1",
    "express-redis-cache": "*",
    "foundation-sites": "~5.5.3",
    "fs-extra": "~0.8.1",
    "node-rest-client": "~1.5.1",
    "node-sass": "*",
    "path": "*"
  },
  "devDependencies": {
    "babel-eslint": "^4.1.6",
    "eslint": "^1.10.3",
    "eslint-config-airbnb": "^2.1.1",
    "eslint-config-airbnb-es5": "^1.0.8",
    "eslint-plugin-react": "^3.13.1",
    "nodemon": "~1.8.1",
    "parallelshell": "~2.0.0",
    "watch": "~0.17.1"
  }
}
Run Code Online (Sandbox Code Playgroud)

我试过这个.但它不起作用.它给出了错误.

       "scripts": {
    "start": "nodemon({ script: 'server.js' }).on('restart', function () {console.log('nodemon started');}).on('crash', function () {console.log('script crashed for some reason');});",
    "lint": "eslint"
  },
Run Code Online (Sandbox Code Playgroud)

小智 38

您可以使用exec选项在nodemon保存代码时运行测试.这是一个例子:

nodemon server.js --exec 'npm run test && node'
Run Code Online (Sandbox Code Playgroud)

这将导致nodemon运行npm run test && node server.js,并且在所有测试成功运行之前它不会启动服务器.


Ami*_*mir 5

我使用Standard.js进行linting,我可以nodemon使用下面的package.json脚本来使用它.

"scripts": {
  "lint": "standard",
  "dev": "nodemon ./app --exec \"npm run lint && node\""
  "start": "nodemon ./app"
}
Run Code Online (Sandbox Code Playgroud)

当我跑步时npm run dev,我所做的任何改变都将受到监控和修改.我在Windows使用中测试了这个PowerShell.