javascript - GruntJS, Multiple Tasks and grunt.option -


i starting use gruntjs 1 of projects. have accomplished write simple build script using simple aliases.

however script contains many tasks same, difference parameters source folder , destination folder.

for example:

    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 achieve have 1 task , pass parameters (dest,src) task.

i tried implement using multitasks:

grunt.registertask('sass2', 'run 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 outputs right values params, html3 sass gets compiled.

i not understand why 1 of projects gets compiled , how fix this.

perhaps there way solve problem. better way. maybe using templates?

any kind of or tips appreciated.

thank you!

only last configuration used because grunt.task.run queues them run after current task complete. api:

enqueue 1 or more tasks. every specified task in tasklist run after current task completes, in order specified

what have is:

  • set config 1
  • set config 2
  • set config 3
  • run 3 tasks using active config, #3.

instead, can dynamically create lots of config sections , run tasks:

grunt.config.set('sass.' + proj + '.files', [{     src: 'sass/' + proj + '.sass',     dest: 'build/' + proj + '/css/main.css' }]); 

and call runtask newly-created section:

grunt.task.run('sass:' + proj); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -