Gruntfile 错误,出了什么问题?

Gruntfile error, what is wrong?

我在尝试执行 grunt 时遇到此错误

     $ grunt
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected token :
Warning: Task "default" not found. Use --force to continue.

由于警告而中止。

我的grunt文件如下:

module.exports = function(grunt) {
  grunt.initConfig({
    cssmin: {
      target: {
        files: {[
          expand: true,
          cwd: '/css',
          src: [ '*.css', '!*min.css.' ],
          ext: '.min.css'
        ]}
      }
    }
    watch: {
      sass: {
        files: ['sass/*.sass'],
        tasks: ['sass'],
      },
    },
  });
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.registerTask('default', ['watch']);
};

我的所有依赖项都已正确安装并在 package.json 中。我已经将所有内容都剥离到这个测试文件中,我通常会有更多任务。我已经用 coffeescript 重写了它,但无济于事。为 grunt.registerTask() 传递任何值都会引发指定值的错误,而不是默认值。

有什么想法吗?

您有几个语法错误。一个是 "watch" 之前缺少逗号,另一个是 "cssmin" 任务中的 "files" 数组。

这应该有效:

module.exports = function(grunt) {
  grunt.initConfig({
    cssmin: {
      target: {
        files: [{
          expand: true,
          cwd: '/css',
          src: [ '*.css', '!*min.css.' ],
          ext: '.min.css'
        }]
      }
    },
    watch: {
      sass: {
        files: ['sass/*.sass'],
        tasks: ['sass'],
      },
    },
  });
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.registerTask('default', ['watch']);
};