diff --git a/examples/template-common.js b/examples/template-common.js index b67dbfce274..a46379869ed 100644 --- a/examples/template-common.js +++ b/examples/template-common.js @@ -20,11 +20,12 @@ const hashRegexp = /Hash: [a-f0-9]+/g; exports.replaceBase = (template) => { - let cwd = process.cwd(); + const cwd = process.cwd(); let webpack = path.join(__dirname, ".."); let webpackParent = path.join(__dirname, "..", ".."); - cwd = lessStrict(cwd.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")); - cwd = new RegExp(cwd, "g"); + const cwdRegExpStr = lessStrict(cwd.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")); + const cwdRegExp = new RegExp(cwdRegExpStr, "g"); + const cwdSlashRegExp = new RegExp(cwdRegExpStr + "[\\/\\\\]", "g"); webpack = lessStrict(webpack.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")); webpack = new RegExp(webpack, "g"); webpackParent = lessStrict(webpackParent.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")); @@ -33,7 +34,8 @@ exports.replaceBase = (template) => { return template .replace(/\r\n/g, "\n") .replace(/\r/g, "\n") - .replace(cwd, ".") + .replace(cwdSlashRegExp, "./") + .replace(cwdRegExp, ".") .replace(webpack, "(webpack)") .replace(webpackParent, "(webpack)/~") .replace(timeRegexp, "")