outaTiME / grunt-replace

Replace text patterns with applause.
MIT License
411 stars 47 forks source link

How to use task parameters as replacement string? #95

Closed vargaendre closed 7 years ago

vargaendre commented 7 years ago

Hi, I'd like to pass in parameters for the replacement. So I'm using this for setting the server's URL in different environments. Would be nice to pass the parameter URL. Is this possible?

outaTiME commented 7 years ago

Hi pal, you can do this in the grunt way:

replace: {
  dev: {
    options: {
      patterns: [
        {
          server_uri: 'localhost'
        }
      ]
    },
    files: [
      {expand: true, flatten: true, src: ['src/**/*.js'], dest: 'build/'}
    ]
  }
  dist: {
    options: {
      patterns: [
        {
          server_uri: 'prod.domain.com'
        }
      ]
    },
    files: [
      {expand: true, flatten: true, src: ['src/**/*.js'], dest: 'build/'}
    ]
  }
}

Alternatively you could use something like grunt-config in conjunction with grunt-replace:

https://www.npmjs.com/package/grunt-config#environment-variable-in-source-with-grunt-replace-

vargaendre commented 7 years ago

Thank you for the quick answer! Right now I'm doing it 'the grunt way', but I think it involves a lot of boilerplate. The alternative version looks cool, I check it out. Thanks!