Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using output of one task as an input for another

Tags:

gruntjs

I have an html file that contains references to js files. I want to parse it extract a list of referenced js files and feed contrib-concat or any other task with them. Is there any convenient way to use output of one grunt task as an input for another?

like image 974
Ivan Buryak Avatar asked Apr 02 '13 06:04

Ivan Buryak


1 Answers

Use grunt.config. Here is an example:

grunt.initConfig({
  concat: {
    js: {
      src: ['default/concat/files/*'],
      dest: ['dist/javascript.js'],
    },
  },
});
grunt.registerTask('extractjs', function() {
  /* Do the js extraction */
  // Overwrite the concat.js.src with your extracted files.
  grunt.config(['concat', 'js', 'src'], extractedFiles);
});

So now when you run grunt extractjs concat it will extract the js and then concat the extracted js files. Check out this task: https://github.com/cgross/grunt-dom-munger as he is working on a similar goal. Here is a grunt issue with more examples as well: https://github.com/gruntjs/grunt/issues/747

like image 113
Kyle Robinson Young Avatar answered Sep 26 '22 10:09

Kyle Robinson Young