带有 Lint Watch 的 Angular-CLI 服务 [英] Angular-CLI Serve with Lint Watch

查看:37
本文介绍了带有 Lint Watch 的 Angular-CLI 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ng serve 期间观察文件更改时,有什么方法可以运行 ng lint 吗?为了鼓励根据 Angular 2 样式指南的最佳实践,我们的 CI 工具在构建过程中运行 ng lint,并且在提交拉取请求之前,开发人员并不总是首先想到运行 lint.

Is there any way to run ng lint while watching for file changes during ng serve? To encourage best practices according to the Angular 2 Style Guide our CI tool runs ng lint during the build process and it isn't always a developers first thought to run lint before submitting a pull request.

是否可以自定义 ng serve 的功能,或者是否有人想出一种方法将运行 lint 作为重新编译过程的一部分?如果不是,我也很想知道其他人是否对这是否是一个好主意以及为什么有任何意见.

Is it possible to customize what ng serve does or has anyone figured out a way to include running lint as part of the recompilation process? If not, I'd also be interested in knowing whether others have any opinions on whether this is a good idea or not and why.

推荐答案

您可以为此使用 nodemon 定义一个带有监视的附加 npm 脚本.

You can define an additional npm script with a watch using nodemon for this.

  1. 全局安装 nodemon npm 包 (npm i -g nodemon) 或在您的项目中安装 (npm i --save-dev nodemon)
  2. 在 package.json 中定义 npm 脚本(在 "scripts" 下):`

  1. Install nodemon npm package globally (npm i -g nodemon) or in your project (npm i --save-dev nodemon)
  2. Define the npm script in package.json (under "scripts"): `

"lint:watch": "nodemon --exec \"npm run lint ||退出 1\" --ext ts,html,scss"

运行 npm run lint:watch

您可以将 --ext ts,html,scss,json 更改为您想要重新启动 lint 的任何文件扩展名.有关 nodemon 的更多文档,请参阅 https://github.com/remy/nodemon#nodemon

You can change the --ext ts,html,scss,json to whatever file extensions you want to cause lint to restart. For further documentation of nodemon, see https://github.com/remy/nodemon#nodemon

这篇关于带有 Lint Watch 的 Angular-CLI 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆