JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 276980
  • Score
    100M100P100Q174681F
  • License MIT

Replace loader for Webpack

Package Exports

  • string-replace-loader

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (string-replace-loader) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Replace loader for Webpack

Perform replacements (plain and regular expression) in the contents loaded by the loader.

Install:

$ npm install --save-dev replace-loader

Usage:

Plain replacement:

In your webpack.config.js:

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

Regex replacement:

To achieve regular expression replacement you should specify the flags query param (as an empty string if you do not want any flags). In this case, search and flags are being passed to the RegExp constructor.

In your webpack.config.js:

module.exports = {
    // ...
    module: {
      loaders: [
        {
          test: /fileInWhichJQueryIsUndefined\.js$/,
          loader: 'string-replace',
          query: {
            search: 'jquery',
            replace: 'window.$',
            flags: 'i'
          }
        }
      ]
    }
}

Contributing:

Feel free to open issues to propose stuff and participate. Pull requests are also welcome.

Licence:

MIT