How can I use two "replace" tasks from "grunt-replace" and "grunt-text-replace" in same gruntfile.js

2k views Asked by At

In my gruntfile I use grunt-replace for replace tags starting from @@. But I want to find custom strings and replace them too. So I found that grunt-text-replace is suitable for that. I tested it with a demo project. But in this case grunt-replace and grunt-text-replace has same task name "replace". So is it possible to use those two in same gruntfile?

If yes, How?

grunt-text-replace code:

replace: {                                                                  

    bust: {                                                                 
        src: ['dist/*.html'],                                               
        overwrite: true,                 // overwrite matched source files  
        replacements: [                                                     
            {                                                               
                from: '.js',                                                

                to: function () {                                           
                    timeStamp = '.' + new Date().getTime() ;                
                    return timeStamp + '.js';                               
                }                                                           
            }                                                               
        ]                                                                   
    }                                                                       
}        

grunt-replace code:

replace: {
    prod:{                                                                                               
        options: {                                                                                        
            patterns: [{              
                match:'stylelink',                                                                   
                replacement: "<link rel='stylesheet' type='text/css'  id='css' href='css/style.css'>"         
            }]
        }, 
        files: [{expand: true, flatten: true, src: ['app/index.html'], dest: '<%= dirs.dest %>'}]
        } 
    }
1

There are 1 answers

0
Ivan Hristov On BEST ANSWER

One way is to rename the task before loading the second plugin. Take a look at: grunt.task.renameTask

Also here is an example: StackOverFlow