Gruntjs GrunFile.js动态构建文件对象

Gruntjs GrunFile.js动态构建文件对象,gruntjs,Gruntjs,问题:在Grunt项目的“配置任务”页面上,为任务指定文件的“文件对象格式”方式起作用,而“文件数组格式”以及关键的“动态构建文件对象”方式(请参见其列表中的“动态映射”部分)不起作用 问题:为什么清单2不起作用?Grunt页面上的动态文件构建示例是否错误 参考:位于的Grunt项目页面 底部是GrunFile.js的两个列表。第一个不起作用,而第二个起作用。它们之间的唯一区别在于各自如何指定“文件”任务: 。。。一个有效的方法是: files: { expand: true, cwd:

问题:在Grunt项目的“配置任务”页面上,为任务指定文件的“文件对象格式”方式起作用,而“文件数组格式”以及关键的“动态构建文件对象”方式(请参见其列表中的“动态映射”部分)不起作用

问题:为什么清单2不起作用?Grunt页面上的动态文件构建示例是否错误

参考:位于的Grunt项目页面

底部是GrunFile.js的两个列表。第一个不起作用,而第二个起作用。它们之间的唯一区别在于各自如何指定“文件”任务:

。。。一个有效的方法是:

files: {
  expand: true,
  cwd: 'views/',
  src: ['**/*.jade'],
  dest: 'html/',
  ext: 'html',
},
唯一的区别在于“[”和“]”的存在/不存在

第二个列表不起作用,但它遵循Grunt项目页面上的示例

清单#1(不起作用): 使用“警告:对象#没有方法'indexOf'Use--force继续”中止

module.exports=函数(grunt){
grunt.initConfig({
杰德:{
选项:{pretty:true,
数据:{
是的,
时间戳:“
}
},
档案:[{
是的,
cwd:“视图/”,
src:['**.jade'],
dest:'html/',
分机:“html”,
}],
},
观察:{
html:{
文件:['handlers/***/.js','views/***/.jade','app.js'],
任务:['jade']
}
}
});
grunt.loadNpmTasks(“grunt-contrib-jade”);
grunt.loadNpmTasks(“grunt-contrib-watch”);
registerTask('default',['jade','watch']);
}
清单2(作品)

module.exports = function(grunt) {

    grunt.initConfig({

        jade: {
            options: { pretty: true,
                data: {
                  debug: true,
                  timestamp: "<%= grunt.template.today() %>"
                }
            },
            files: {
              expand: true,
              cwd: 'views/',
              src: ['**/*.jade'],
              dest: 'html/',
              ext: 'html',
            },
        },

        watch: {
            html: {
                files: ['handlers/**/*.js', 'views/**/*.jade', 'app.js'],
                tasks: ['jade']
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-jade');
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.registerTask('default', ['jade', 'watch']);

}
module.exports=函数(grunt){
grunt.initConfig({
杰德:{
选项:{pretty:true,
数据:{
是的,
时间戳:“
}
},
档案:{
是的,
cwd:“视图/”,
src:['**.jade'],
dest:'html/',
分机:“html”,
},
},
观察:{
html:{
文件:['handlers/***/.js','views/***/.jade','app.js'],
任务:['jade']
}
}
});
grunt.loadNpmTasks(“grunt-contrib-jade”);
grunt.loadNpmTasks(“grunt-contrib-watch”);
registerTask('default',['jade','watch']);
}
  • “lucky”=周末阅读了数百页关于解析错误、grunt、jade、express、JavaScript、函数和对象的页面。。。最后决定,既然每一个合理的努力都失败了,唯一可以尝试的就是不合理的努力
答案(在我发布问题后添加):

CONFIG(grunt.initConfig)所需的结构是:

所以这不应该起作用(但是……我很幸运*):

。。。而这不应该起作用(而且……呼!):

最后,这应该而且确实有效(哈利路亚):


我有一个类似的问题,并在这篇文章中找到了答案(在我重新安排了这里发布的结构之后)

基本上,答案是将files指令的定义部分包装为数组。 而不是

files:{...}  
使用


对落选者来说,落选是针对以下问题的:(1)“没有显示任何研究成果;(2)不清楚;(3)或者没有用处。我希望有人会认为我的问题不符合要求(1)。这也很清楚,符合要求2。关于(3),我显然花了大量的时间来研究这个问题,记录问题,然后回来记录解决方案,以避免其他一些糟糕的sap因同一问题而陷入疯狂。我建议你假设提问的人是出于善意,或者暂停投票。
module.exports = function(grunt) {

    grunt.initConfig({

        jade: {
            options: { pretty: true,
                data: {
                  debug: true,
                  timestamp: "<%= grunt.template.today() %>"
                }
            },
            files: {
              expand: true,
              cwd: 'views/',
              src: ['**/*.jade'],
              dest: 'html/',
              ext: 'html',
            },
        },

        watch: {
            html: {
                files: ['handlers/**/*.js', 'views/**/*.jade', 'app.js'],
                tasks: ['jade']
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-jade');
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.registerTask('default', ['jade', 'watch']);

}
 CONFIG
    TASK
       TARGET
          FILES               // MUST be child of a target
          OPTIONS             // MUST be child of a target
 grunt.initConfig
    jade: {
       files: {...           // all info content required for jade...
     options: ...            // is specified in these two elements
 grunt.initConfig
    jade: {
       files: [ {...
     options: ...
 grunt.initConfig
    jade: {
      foo: {      // MUST have target, though no addn'l info added. why? just because.
         files: ...
         options: ...
files:{...}  
files:[{...}]