Reputation: 308
I just started using grunt, and I search a way to declare files option more dynamically
my config is
handlebars: {
compile: {
options: {
namespace: Handlebars.Template',
files: {
"public/media/js/module1/precompiledTemplates.js": "public/media/js/module1/templates/*.hbs",
"public/media/js/module2/precompiledTemplates.js": "public/media/js/module2/templates/*.hbs ",
"public/media/js/module3/precompiledTemplates.js": "public/media/js/module3/templates/*.hbs "
}
},
I've got lots of modules, is there a way to declare something like that ?
files: {
"public/media/js/$1/precompiledTemplates.js": "public/media/js/(*.)/templates/*.hbs"
}
I took a look at this , but i do not find the right way to manage this "problem".
Upvotes: 0
Views: 91
Reputation: 308
I have a solution based on the previous comment :
You must have a normal configuration about handlebars.compile (or the plugin used). And add a custom task and build files object in javascript.
grunt.registerTask('hbs_compile', 'Your custom task', function() {
var myFiles = {};
// ... here you build your myFiles object, see grunt.file api ...
// in my case :
grunt.file.expand('my/modules/path/*').forEach(function (basePath) {
myFiles[basePath + '/precompiledTemplates.js'] = basePath + '/templates/*.hbs'
})
// and you overide the configuration with your object
grunt.config.set('handlebars.compile.files', myFiles);
grunt.task.run('handlebars:compile');
});
Now, can you run in CLI :
$ grunt hbs_compile
and add modules less reconfigure grunt.
Upvotes: 1