在 angular 中编译之前如何 运行 ts-lint?

How to run ts-lint when before compiling in angular?

当 运行ning ng serve 时,angular cli 会监视更改并重新编译项目。对我来说,如果 ng lint 在文件更改中也可以是 运行 会很有帮助。当然,如果只检查更改的文件就更好了。

您可以为此使用 nodemon 定义一个额外的 npm 脚本。

全局安装 nodemon npm 包 npm i -g nodemon 或者在你的项目中 npm i --save-dev nodemon 在 package.json 中定义 npm 脚本(在“脚本”下):`

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

定义另一个脚本"serve-lint": "npm run serve && npm run lint:watch"

运行 npm run serve-lint