Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

string-replace-webpack-plugin

jamesandersen48.1kMIT0.1.3TypeScript support: definitely-typed

Replace string tokens in the contents of a file.

webpack, string, replace, plugin

readme

string replace plugin for webpack

Usage example

var StringReplacePlugin = require("string-replace-webpack-plugin");
module.exports = {
   module: {
      loaders: [
         // configure replacements for file patterns
         { 
            test: /index.html$/,
            loader: StringReplacePlugin.replace({
                replacements: [
                    {
                        pattern: /<!-- @secret (\w*?) -->/ig,
                        replacement: function (match, p1, offset, string) {
                            return secrets.web[p1];
                        }
                    }
                ]})
            }
      ]
   },
   plugins: [
      // an instance of the plugin must be present
      new StringReplacePlugin()
   ]
}

This allows for arbitrary strings to be replaced as part of the module build process. The original intent is to replace API keys in modules prior to deployment.

API

StringReplacePlugin.replace([nextLoaders: string], options, [prevLoaders: string])
  • nextLoaders loaders to follow the replacement
  • options
    • replacements disables the plugin
  • prevLoaders loaders to apply prior to the replacement

License

MIT (http://www.opensource.org/licenses/mit-license.php)

changelog

v0.1.3

  • Preserve source map after replacement (@rnons)

v0.1.2

  • Don't save options on the compiler for Webpack 2.2 compatibility (@CntChen)

v0.1.0

  • API docs fix (@p2227)
  • Dependency update to webpack >=2.2.0-rc.0 (@RomanGotsiy)
  • Bump to minor version

v0.0.4

  • Move sample loaders to optionalDependencies (@at0g)

v0.0.3

  • Correct string type check (@mhodgson)

v0.0.2

  • Preserve loader "this" context for "replacement" function (@mdreizin)

v0.0.1 - Initial Release