Va1 / string-replace-loader

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

How can I get a file name in the replace fn? #73

Closed michaltaberski closed 2 years ago

michaltaberski commented 2 years ago

I is it possible to retrieve information about the file context where the replace is happening? Just like this:

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: 'string-replace-loader',
        options: {
          search: '%%FILE_PATH%%',
          replace(match, p1, offset, string) {
            // Is there a way to get FULL_FILE_PATH like `/src/components/button.js?
            // the file that match rule's test 
            return FULL_FILE_PATH;
          },
          flags: 'g'
        }
      }
    ]
  }
}
Va1 commented 2 years ago

duplicate: https://github.com/Va1/string-replace-loader/issues/66

this feature was implemented and released as v3.1.0. check the docs. thank you.