Skip to content
Replace string tokens in a bundle.
Branch: master
Clone or download
#31 Compare This branch is 43 commits ahead, 226 commits behind webpack-contrib:master.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea
example update example webpack config to meet webpack2 Feb 22, 2017
.gitattributes
.gitignore Adding WebStorm project data to source control Mar 24, 2015
.npmignore
CHANGELOG.md
README.md
index.js
loader.js
package.json 0.1.3 Mar 7, 2017
test.js

README.md

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)

You can’t perform that action at this time.