2013-03-20 30 views
31

剛剛在Ubuntu 12.04上安裝了最新的Grunt。這裏是我的gruntfile:Grunt Concat無法寫入文件

module.exports = function(grunt){ 
//project configuration 
grunt.initConfig({ 
    pkg: grunt.file.readJSON('package.json'), 

    concat: { 
     slides : { 
      src : ['src/top.html', 'src/bottom.html'], 
      dest : ['build/index.html'] 
     } 
    } 
}); 

//enable plugins 
grunt.loadNpmTasks('grunt-contrib'); 
grunt.registerTask('default', ['concat:slides']); 
} 

這在構建/目錄罰款,但給我的輸出:

運行 「CONCAT:幻燈片」(CONCAT)任務警告:無法寫入 「 build/index.html「文件(錯誤代碼:undefined)。繼續使用 - force至 。

我試着在目錄上運行chmod 777,因爲我認爲它可能與權限有關,但似乎沒有改變任何東西。

我該如何讓Grunt寫入build/index.html?

回答

82

想通了:

//Does not work 
dest : ['build/index.html'] 

作品作爲字符串,但不是數組:

//Works 
dest : 'build/index.html' 
+1

我有同樣的問題,找到了類似的問題,並根據您的答案給出了[詳細解答](http://stackoverflow.com/a/17626981/1092815)。所有學分去給你,非常感謝:) – GabLeRoux 2013-07-13 04:32:16

+0

這個答案幫助我解決了另一個語法錯誤。確保使用'dest'而不是'dst'。 – 2013-08-23 12:04:08

+0

謝謝,真的救了我培根......時間明智:) – 2014-03-21 19:46:12

0

我改變任務/ concat.js接受DEST數組:

// Write the destination file. 
// If f.dest is an array take the first element 
var dest = ([].concat(f.dest))[0] 
grunt.file.write(dest, src); 

但後來我決定使用文件格式代替src/dest:

files: { 'dest.js': ['a.js', 'b.js'] }