I am starting to use GruntJS for one of my projects. I easily recorded a simple build script using simple aliases.
However, my script contains many tasks that are basically the same, the only difference is some options, such as the source folder and destination folder.
For instance:
sass: { options:{ trace: true, debugInfo: true, style: 'compressed' }, html: { files: { 'build/html/css/main.css': 'sass/html.sass' } }, html2: { files: { 'build/html2/css/main.css': 'sass/html2.sass' } }, html3: { files: { 'build/html3/css/main.css': 'sass/html3.sass' } } }
What I would like to achieve is to have only one task, and then pass the parameters (dest, src) to this task.
I tried to implement this with MultiTasks:
grunt.registerTask('sass2', 'Run all Sass compilation tasks.', function() { var projects = ['html','html2','html3']; projects.forEach(function(proj){ grunt.config.set('sass.files.dest', 'build/' + proj + '/css/main.css'); grunt.config.set('sass.files.src', 'sass/' + proj + '.sass'); grunt.log.writeln(grunt.config.get('sass.files.dest')); grunt.log.writeln(grunt.config.get('sass.files.src')); grunt.task.run('sass'); }); });
Grunt log displays the correct values ββfor the parameters, however only html3 sass is compiled.
I donβt understand why only one of the projects compiles and how I can fix it.
Perhaps there is another way to solve this problem. The best way. Perhaps the use of templates?
Any help or advice would be helpful.
Thanks!