Grunt task to modify javascript file

I have the following node.js javascript file.

module.exports = function(){
    ...
    var config1 = "";
    var config2 = "";
    var config3 = "";
    ...
}

      

Suppose I have the following task:

grunt.registerTask('task1', ['...',copy]);
grunt.registerTask('task2', ['...',copy]);
grunt.registerTask('task3', ['...',copy]);

      

Depending on the task I'm running, the config value config1, config2, config3 needs to be changed.

For example:

grunt task1

      

should produce

module.exports = function(){
    ...
    var config1 = "A";
    var config2 = "B";
    var config3 = "C";
    ...
}

      

while grunt task2

should produce

module.exports = function(){
    ...
    var config1 = "X";
    var config2 = "Y";
    var config3 = "Z";
    ...
}

      

Is there any grunt plugin out there that can do this or similar?

+3


source to share


1 answer


For simple things like this, I just use grunt-replace. Give it a regex to find each line and line to replace that line with what you want to get. This doesn't actually parse your code, although if you do some refactoring later, you'll need to change the regex.



+2


source







All Articles