Q:

How can i change the line content with another with grunt?

I have a simple task,
when i write the command "grunt build" i want this 2 lines to change state, like so:
before the command:
        baseUrl : 'http://localhost:3000/'
        //baseUrl : 'http://188.166.18.108/'

after the command 
        //baseUrl : 'http://localhost:3000/'
        baseUrl : 'http://188.166.18.108/'

end of build change back to:
        baseUrl : 'http://localhost:3000/'
        //baseUrl : 'http://188.166.18.108/'

Is it anyway possible with grunt to do so? thanks guys!

A:

You should try using grunt-string-replace, like this:
'string-replace': {
  dist: {
    files: {
      src: 'path/to/your/file',
      dest: 'path/to/your/file'
    },
    options: {
      replacements: [{
        pattern: "baseUrl : 'http://localhost:3000/'",
        replacement: "baseUrl : 'http://188.166.18.108:3000/'"
      }]
    }
  }
}

Then you can have only one line in your file, without having to comment it.
baseUrl : 'http://localhost:3000/'

Also, if you want to replace all occurrences of localhost, you can use it as a pattern and it will replace all to your IP address:
...
pattern: "localhost",
replacement: "188.166.18.108"
...

For changing back from the IP address to localhost you can add a new task for string replace and run both in your build. It will be something like:
'string-replace': {
  prev: {
    files: {
      src: 'path/to/your/file',
      dest: 'path/to/your/file'
    },
    options: {
      replacements: [{
        pattern: "baseUrl : 'http://localhost:3000/'",
        replacement: "baseUrl : 'http://188.166.18.108:3000/'"
      }]
    }
  },
  after: {
    files: {
      src: 'path/to/your/file',
      dest: 'path/to/your/file'
    },
    options: {
      replacements: [{
        pattern: "baseUrl : 'http://188.166.18.108:3000/'",
        replacement: "baseUrl : 'http://localhost:3000/'"
      }]
    }
  }
}

And then run it like:
grunt.registerTask('replace', ['string-replace:prev', 'string-replace:after']);

