2014-10-07 64 views
0

我是新來的grunt,並試圖將它安裝在一個簡單的項目上。它的工作,但是當我嘗試「ugilfy」我的文件來看,我不斷收到此錯誤:GruntJS:不能調用未定義的方法過濾器

cannot call method 'filter' of undefined' 

這是我咕嚕文件(Gruntfile.js),保存在我的項目的根目錄:

module.exports = function(grunt) 


{ 

grunt.initConfig({ 

    uglify: 
    { 
     options: 
     { 
      mangle: true, 
      compress:true, 
      sourceMap: "dist/app.map", 
      banner: "/* 2014 */" 
     }, 

     //set of files where the plugin works on, (files which we can affect with our plugins like uglify) 
     // culd be dev or production 
     target: 
     { 

      //folder name equal to the JS object!!! 
      js: "js/app.js", 
      dest: "dist/app.min.js" 
     } 
    } 

}); 



//load plug-ins 
grunt.loadNpmTasks('grunt-contrib-uglify'); 


}; 

我嚴重不知道爲什麼它不工作。我試圖搜索谷歌,但我找不到任何答案。

+0

聽起來像它不喜歡你的一些Javascript。 'grunt --force'對你有幫助嗎? – Ben 2014-10-07 13:29:32

+0

還沒有工作:(我得到了相同的警告,但沒有創建文件:/ – Marciano 2014-10-07 14:45:33

+0

好吧,這是遠射,你需要檢查你的Javascript,像jslint.com這樣的工具將有所幫助 – Ben 2014-10-07 19:40:07

回答

0

uglify.target缺少src屬性。

變化

js: "js/app.js", 

src: "js/app.js", 

,它應該正常工作。

有關指定來源和目的地的更多信息,請參閱in the Grunt docs

+0

嘿,那工作!!: )它總是被稱爲'src'嗎?我認爲這取決於你的文件夾名稱。 非常感謝! – Marciano 2014-10-20 22:08:10

+0

很高興爲您效勞!請參閱[docs on file mappings](http://gruntjs.com/configuring-tasks#files)瞭解可以指定這些內容的不同方式(因爲有多個),但通常,如果您有'dest',你需要一個'src'。 – myersjustinc 2014-10-21 14:27:34

相關問題