Angular-CLI与Lint手表搭配使用 [英] Angular-CLI Serve with Lint Watch
问题描述
在 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服务
的作用,还是有人想出一种方法来将运行中的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.
- 在全局(
npm i -g nodemon
)或项目(npm i --save-dev nodemon
)中安装nodemon npm软件包 -
在package.json中定义npm脚本(在
"scripts"
下):`
- Install nodemon npm package globally (
npm i -g nodemon
) or in your project (npm i --save-dev nodemon
) Define the npm script in package.json (under
"scripts"
): `
"lint:watch":"nodemon --exec \" npm run lint ||退出1 \---ext ts,html,scss"
运行 npm运行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
这篇关于Angular-CLI与Lint手表搭配使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!