同様の問題がありました。特定のパスパターンで同じファイル名のファイルが検出された場合、ビルドが失敗するようにしたかったのです。カスタムタスクを書くことで解決しました。grunt.file.expand または grunt.file.recurse GruntAPIを使用できます
多分これはあなたを助けるでしょう(これはjsではなくcoffeescriptです)。
grunt.registerMultiTask "noduplicates", "Detects duplicated filenames", () ->
path = require('path')
dupFilenamesCounted = {}
haveDuplicates = false
options =
cwd: this.data.cwd
grunt.file.expand(options, this.data.src).forEach (filepath) ->
filepathParts = filepath.split(path.sep)
filename = filepathParts.slice(-1).join(path.sep)
unless dupFilenamesCounted[filename] is undefined
dupFilenamesCounted[filename].counter++
dupFilenamesCounted[filename].filepaths.push(filepath)
else
dupFilenamesCounted[filename] = { counter: 0, filepaths: [ filepath ] }
for filename of dupFilenamesCounted
if dupFilenamesCounted[filename].counter > 0
grunt.log.error "Filename: " + filename + ' has ' + dupFilenamesCounted[filename].counter + ' duplicates: ' + dupFilenamesCounted[filename].filepaths
haveDuplicates = true
# Fail by returning false if this task had errors
return false if haveDuplicates
次に、タスクを定義します。
noduplicates:
images:
cwd: '<%= pkg.src %>'
src: [ 'static/**/*.{gif,png,jpg,jpeg}' ]