找不到任务和子任务

时间:2013-10-25 21:21:05

标签: javascript gruntjs

我刚刚开始使用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.

当我开始使用它时,我看了一下doc并且无法找到我可能出错的地方......是的,依赖项已正确安装。

1 个答案:

答案 0 :(得分:5)

您需要确保在initConfig部分之后注册任务。

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