GRUNT | Error: Unable to compile; no valid source files were found

GRUNT | Error: Unable to compile; no valid source files were found

我已经安装了 Graphicmagik 并创建了以下 Gruntfile.js:

module.exports = function(grunt) {

  grunt.initConfig({
    responsive_images: {
      dev: {
        options: {
          engine: 'gm',
          sizes: [{width: 320, name: 'small'},
                  {width: 640, name: 'medium'},
                  {width: 800, name: 'large' }
                  ]
        }
      },

        /*
        You don't need to change this part if you don't change
        the directory structure.
        */
        files: [{
          expand: true,
          src: ['**/*.jpg'],
          cwd: 'images_src/',
          dest: 'images/'
        }]

    },

    /* Clear out the images directory if it exists */
    clean: {
      dev: {
        src: ['images'],
      },
    },

    /* Generate the images directory if it is missing */
    mkdir: {
      dev: {
        options: {
          create: ['images']
        },
      },
    },

    /* Copy the "fixed" images that don't go through processing into the images/directory */
    copy: {
      dev: {
        files: [{
          expand: true,
          src: 'images_src/fixed/*.{gif,jpg,png}',
          dest: 'images/'
        }]
      },
    },
  });

  grunt.loadNpmTasks('grunt-responsive-images');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-mkdir');
  grunt.registerTask('default', ['clean', 'mkdir', 'copy', 'responsive_images']);

};

项目文件夹树:

project
  css
  images_src
    fixed
  node_modules
    grunt-contrib-clean
    grunt-contrib-copy
    grunt-contrib-mkdir
    grunt-responsive-images
    "other grunt dependencies"

当我 $grunt responsive_images 时,出现以下错误:

Running "responsive_images:dev" (responsive_images) task
>> Unable to compile; no valid source files were found.
>> Unable to compile; no valid source files were found.
>> Unable to compile; no valid source files were found.
Running "responsive_images:files" (responsive_images) task
Fatal error: Unable to read configuration.
Have you specified a target? See: http://gruntjs.com/configuring-tasks

cwd 和 src 改了好几次都没用!我知道 cwd ('current working directory') 是存储图像的文件夹,src 是我识别要转换的 file/file 扩展名的地方。所以我认为这个设置是正确的。但是为什么会报这个错呢?

这些文件是在 responsive_images:dev 目标之外定义的。将 files 块移动到 dev 目标内以修复:

responsive_images: {
  dev: {
    options: {
      engine: 'gm',
      sizes: [{width: 320, name: 'small'},
              {width: 640, name: 'medium'},
              {width: 800, name: 'large' }
              ]
    },
     files: [{
      expand: true,
      src: ['**/*.jpg'],
      cwd: 'images_src/',
      dest: 'images/'
    }],
  },
},