Question: I am using `webpack 3` & trying to use [string replace loader](https://www.npmjs.com/package/string-replace-loader). 

This code use to work in webpack1.X

```
module: {
    loaders: [
      {
        test: /fileName\.js$/,
        loader: 'string-replace',
        query: {
          search: 'jQuery',
          replace: 'window.$'
        }
      }
    ]
  }

```

I have tried this as well:

```
module: {
        loaders: [
          {
            test: /fileName\.js$/,
            loader: 'string-replace-loader',
            query: {
              search: 'jQuery',
              replace: 'window.$'
            }
          }
        ]
      }

```

What do I need to do to ensure this loader works in webpack 3. There are no errors but string is not getting replaced in the target file.

Answer: 
Have you tried adding `flags: 'g'` to the query option:

```
query: {
    search: 'jQuery',
    replace: 'window.$'
    flags: 'g'
}

```
Bug in pattern-replace-loader.
It uses String.proototype.replace() method and it only replaces first entry of the pattern.

Use of flags: 'g' forces it to use RegEx and replace all entries in the file.
See: <https://www.w3schools.com/jsref/jsref_replace.asp>