From c2e0558627b2645559e4351ff0f5823cef9ad89d Mon Sep 17 00:00:00 2001 From: Rowan Oulton Date: Fri, 21 Apr 2017 11:43:18 -0700 Subject: [PATCH] Add optional ID parameter --- README.md | 1 + index.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f6e5b833..0adc9479 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ StringReplacePlugin.replace([nextLoaders: string], options, [prevLoaders: string * `replacements` disables the plugin * `pattern` a regex to match against the file contents * `replacement` an ECMAScript [string replacement function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter) + * `id` an optional id. defaults to a random string * `prevLoaders` loaders to apply prior to the replacement ## License diff --git a/index.js b/index.js index 644c62cf..076dbec1 100644 --- a/index.js +++ b/index.js @@ -36,7 +36,7 @@ StringReplacePlugin.replace = function(nextLoaders, replaceOptions, prevLoaders) throw new Error("Invalid options for StringReplaceOptions. Ensure the options objects has an array of replacements"); } - var id = Math.random().toString(36).slice(2); + var id = replaceOptions.id && replaceOptions.id.length ? replaceOptions.id : Math.random().toString(36).slice(2); opts[id] = replaceOptions; var replaceLoader = require.resolve("./loader") + "?id=" + id, val = replaceLoader;