2013-02-20 114 views
17

Gruntfile.js:咕嚕警告任務 「看」 找不到

grunt.initConfig({ 
watch: { 
    compass: { 
    files: [ 
     'app/styles/**/*.{scss,sass}' 
    ], 
    tasks: 'compass reload' 
    }, 
..... 
grunt.registerTask('dev', 'watch'); 

當我運行

grunt dev 

我得到的錯誤

Warning: Task "watch" not found. Use --force to continue. 

我用咕嚕-CLI V0。 1.6和grunt v0.4.0,安裝了grunt-contrib-watch。

回答

8

好吧。

npm install grunt-contrib --save-dev 

和grunt.js的最後一行之前添加此行:

grunt.loadNpmTasks('grunt-contrib'); 

而且,我已經安裝到Ruby ...

+5

等一下,你不得不安裝整個grunt-contrib庫嗎?這是很多依賴關係。這是最好的解決方案? – 2013-03-21 23:56:32

+1

這不是最好的解決辦法。當然,我不使用所有這些功能。 – Serge 2013-04-01 07:41:02

47

您不必安裝整個貢獻包。有一個單獨的一個手錶

npm install grunt-contrib-watch --save-dev 

,並在年底:

grunt.loadNpmTasks('grunt-contrib-watch'); 
+5

這是正確的,因爲Grunt團隊不建議使用'grunt-contrib',而是單獨使用每個模塊。 – 2013-04-04 18:55:35

0

事實上,如果沒有安裝該插件,你不會有一個錯誤launcinh grunt watch,只是不可能出錯加載watch任務。

0

我知道這個問題是舊的,但它是不正確回答,因爲還指出塞爾

安裝咕嚕-的contrib手錶。

當您關閉這個功能(意外)我會檢查,如果整個Gruntfile由

module.exports = function (grunt) { 

}; 

過早地包裹着你所描述的錯誤。

0

瀏覽器更新和npm更新爲我工作。

0

,當我跑在終端咕嚕手錶,遇到錯誤固定:

錯誤

grunt watch 
Loading "Gruntfile.js" tasks...ERROR 

FIX在終端

brew install npm 
brew install node 
  • 那麼你測試節點和npm工作

    node -v 
    npm -v 
    
  • 安裝咕嚕

    npm install -g grunt-cli 
    npm install grunt-contrib-watch --save-dev 
    
  • 安裝作曲

    curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer 
    
  • 然後跑

    grunt watch 
    

它的工作!