問題: Grunt プロジェクトの「Configuring Tasks」ページで、タスクのファイルを指定する「Files Object Format」の方法は機能しましたが、「Files Array Format」と、重要なことに、「Building the file object dynamic」の方法 (リストの「dynamic_mappings」セクション) はしませんでした。
質問: リスト #2 が機能しないのはなぜですか? Grunt のページにある動的ファイル構築の例は間違っていますか?
参考: Configuring Tasks/Building the Files Object Dynamicallyの Grunt プロジェクト ページ。
下部には、Gruntfile.js の 2 つのリストがあります。最初のものは機能しませんが、2 つ目は機能します。それらの唯一の違いは、それぞれが「ファイル」タスクを指定する方法です。
files: [{
expand: true,
cwd: 'views/',
src: ['**/*.jade'],
dest: 'html/',
ext: 'html',
}],
...動作するものは次のとおりです。
files: {
expand: true,
cwd: 'views/',
src: ['**/*.jade'],
dest: 'html/',
ext: 'html',
},
唯一の違いは「[」と「]」の有無です。
2 番目のリストは機能しませんが、Configuring Tasks / Building the Files Object Dynamicallyの Grunt プロジェクトのページの例に従います。
リスト # 1 (動作しません) : 「警告: オブジェクト # にはメソッド 'indexOf' がありません。続行するには --force を使用してください。」で中止されます。
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']);
}
リスト#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']);
}
- 「ラッキー」 = 解析エラー、grunt、jade、express、JavaScript、関数、およびオブジェクトに関する何百ものページを読んで週末を過ごしました...最終的に、すべての合理的な努力が失敗したため、試す必要があるのは不合理なものだけであると判断しました。