Va1 / string-replace-loader

Replace loader for Webpack
MIT License
250 stars 57 forks source link

Feature request: callbacks #40

Closed balping closed 4 years ago

balping commented 6 years ago

Would be great if I could specify a callback function as a replacement like:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'string-replace-loader',
        options: {
          search: 'my name',
          replace: function(result){
                  return result.toUpperCase();
          },
          flags: 'gi'
        }
      }
    ]
  }
}
Rincewind3d commented 6 years ago

+1

It would be very easy to implement:

After the native String.replace implementation is used you can easy use function in replaced instead of a string. Only the optionsSchema object has to be adjusted to allow also a function.

Rincewind3d commented 6 years ago

Ah I see, you figured it out, too ;) https://github.com/Va1/string-replace-loader/pull/41/commits

Va1 commented 4 years ago

implemented. thanks