2013-10-25 71 views
0

我剛開始使用Grunt,而且我可能有問題。所以,這裏是我的Gruntfile.js是什麼樣子:未找到任務和子任務

module.exports = function (grunt) { 
    grunt.initConfig({ 

    // Ability to access the package.json informations 
    pkg: grunt.file.readJSON('package.json'), 

    // SASS compilation 
    sass: { 
     dist: { 
     options: { 
      style: 'compressed' 
     }, 
     expand: true, 
     cwd: './sass/', 
     src: 'main.scss', 
     dest: './css/', 
     ext: '.css' 
     }, 
     dev: { 
     options: { 
      style: 'expanded', 
      debugInfo: true, 
      lineNumbers: true 
     }, 
     expand: true, 
     cwd: './sass/', 
     src: 'main.scss', 
     dest: './css/', 
     ext: '.css' 
     } 
    } 

    }); 
}; 

當我運行grunt sass:dev,它總是返回我Warning: Task "sass:dev" not found. Use --force to continue.

正如我開始有了它,我的文檔看了看,可以」 t找到我可能出錯的地方......並且,依賴關係已正確安裝。

+0

[任務 「的concat」 在咕嚕沒有發現在Windows]的可能重複(http://stackoverflow.com/questions/15946224/task-concat-not-found-in-grunt-on-windows) – JJJ

回答

4

您需要確保任務在initConfig部分之後註冊。

module.exports = function (grunt) { 
    grunt.initConfig({ 
    // ... 
    }); 
    grunt.loadNpmTasks('grunt-contrib-sass'); 
}; 
+0

好的,好的!我沒有得到,我不得不爲每個沒有被定製的任務做任何事情。謝謝:) – Axiol

+0

不客氣。儘管取決於您使用的插件數量,但您可能需要使用類似load-grunt-tasks(https://github.com/sindresorhus/load-grunt-tasks)的代碼,因此您可以使用require( 'load-grunt-tasks')(grunt);'而不是你所有依賴的長列表。 :) – Ben