Fix InterpolateHtmlPlugin only replacing the first occurrence (#731)

Fixes https://github.com/facebookincubator/create-react-app/issues/625#issuecomment-249320724.
This commit is contained in:
Ville Immonen
2016-09-24 02:28:32 +03:00
committed by Dan Abramov
parent 500fb749e0
commit e41d671bee
2 changed files with 6 additions and 1 deletions

View File

@@ -16,6 +16,7 @@
// https://github.com/ampedandwired/html-webpack-plugin#events
'use strict';
const escapeStringRegexp = require('escape-string-regexp');
class InterpolateHtmlPlugin {
constructor(replacements) {
@@ -29,7 +30,10 @@ class InterpolateHtmlPlugin {
// Run HTML through a series of user-specified string replacements.
Object.keys(this.replacements).forEach(key => {
const value = this.replacements[key];
data.html = data.html.replace('%' + key + '%', value);
data.html = data.html.replace(
new RegExp('%' + escapeStringRegexp(key) + '%', 'g'),
value
);
});
callback(null, data);
}

View File

@@ -22,6 +22,7 @@
],
"dependencies": {
"chalk": "1.1.3",
"escape-string-regexp": "1.0.5",
"opn": "4.0.2"
},
"peerDependencies": {