mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-01-12 22:46:30 +08:00
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:
committed by
Dan Abramov
parent
500fb749e0
commit
e41d671bee
@@ -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);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"chalk": "1.1.3",
|
||||
"escape-string-regexp": "1.0.5",
|
||||
"opn": "4.0.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
Reference in New Issue
Block a user