2014-01-11 60 views
18

這裏是我的Gruntfile.jsGruntfile.js - 任務「默認」找不到

module.exports = function(grunt) { 
    grunt.initConfig({ 
     pkg: grunt.file.readJSON("package.json"), 

     uglify: { 
      options: { 
      mangle: true 
      } 
      build: { 
      src: "js/*.js", 
      dest: "js/min/script.js" 
      } 
     } 

    }); 

    grunt.loadNpmTasks("grunt-contrib-uglify"); 

    grunt.registerTask('default', [uglify]); 

}; 

這是我的package.json - 我已經運行npm install已經與所有的插件,我會在我的Gruntfile中使用,grunt-contrib-uglify就是其中之一。

{ 
    "name": "bootbuckle", 
    "version": "0.1.0", 
    "engines": { 
    "node": ">= 0.10.0" 
    }, 
    "devDependencies": { 
    "grunt": "~0.4.2", 
    "grunt-contrib-watch": "~0.5.3", 
    "grunt-contrib-sass": "~0.6.0", 
    "grunt-csscomb": "~2.0.1", 
    "grunt-contrib-htmlmin": "~0.1.3", 
    "grunt-contrib-imagemin": "~0.4.1", 
    "grunt-contrib-uglify": "~0.2.7" 
    } 
} 

當我只需運行在終端grunt - 這裏是錯誤提前爲您可以提供任何幫助

build: { 
    ^^^^^ 
Loading "Gruntfile.js" tasks...ERROR 
>> SyntaxError: Unexpected identifier 
Warning: Task "default" not found. Use --force to continue. 
Aborted due to warnings. 

感謝。


編輯 繼馬蒂的指導我已經插入缺少逗號,一個新的錯誤,現在被拋出

Loading "Gruntfile.js" tasks...ERROR 
>> ReferenceError: uglify is not defined 
Warning: Task "default" not found. Use --force to continue. 
Aborted due to warnings. 

回答

27

你錯過了一個逗號在這裏:

uglify: { 
     options: { 
     mangle: true 
     }, // <------- 
     build: { 
     src: "js/*.js", 
     dest: "js/min/script.js" 
     } 
    } 

編輯:由japrescott發佈,您必須將uglify任務定義爲字符串。

grunt.registerTask('default', ["uglify"]); 
+1

這就是爲什麼我喜歡用逗號引導。 –

+0

謝謝,我插入了缺失的逗號,btu現在正在拋出一個新的錯誤。編輯上面的帖子來反映這一點。 –

+0

固定。非常感謝! –

10

嘗試這樣

grunt.registerTask('default', ["uglify"]); 
+0

這個和馬蒂的答案的組合固定它。非常感謝! –