2016-01-06 38 views
3

我正在用grunt-eslint插件使用grunt。這是一個較大的咕task任務的一部分,它首先找到更改的文件並使用它們執行各種任務。如果沒有更改任何JS文件(例如,如果我只是更改CSS文件),則整個任務將中止,因爲eslint失敗,並顯示「找不到任何要驗證的文件」消息。如何在沒有找到文件的情況下讓gruntjs跳過eslint任務?

$ grunt eslint:precommit 
Running "eslint:precommit" (eslint) task 
Could not find any files to validate. 
Warning: Task "eslint:precommit" failed. Use --force to continue. 

Aborted due to warnings. 

如果找不到任何JS文件,我不希望任務失敗。

有沒有辦法要麼:

A.有繁重的任務,甚至不叫eslint,而不是如果沒有文件被運行失敗?

B.如果沒有文件運行,Eslan不會失敗?

(相關,但具體到一個從咕嚕叫不同工具:Can an assemble target be silenced if there are no matching files? (Without using --force)

回答

1

使用動態任務是您的解決方案,在這裏的鏈接文檔:http://gruntjs.com/frequently-asked-questions#dynamic-alias-tasks

相關鏈接:

+0

謝謝。因此,如果找不到文件,基本上沒有選項可以跳過任務,但是我可以創建自己的任務來檢查文件並調用我想調用的任務(如果找到它們)?這很好,我只是想讓grunt.file.isMatch現在找到這些文件。 –

+1

它不是grunt.file.isMatch,而是grunt.file.expand,它實際上可以找到文件。在這裏博客:http://www.marcstober.com/blog/2016/01/07/grunt-file-match-and-grunt-file-ismatch-do-not-access-file-system/ –

相關問題