2013-10-25 69 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