Skip to content

Commit 2fe0ba5

Browse files
committed
Normalize backslash on windows
1 parent a0eab48 commit 2fe0ba5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

examples/template-common.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ const hashRegexp = /Hash: [a-f0-9]+/g;
2020

2121
exports.replaceBase = (template) => {
2222

23-
let cwd = process.cwd();
23+
const cwd = process.cwd();
2424
let webpack = path.join(__dirname, "..");
2525
let webpackParent = path.join(__dirname, "..", "..");
26-
cwd = lessStrict(cwd.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
27-
cwd = new RegExp(cwd, "g");
26+
const cwdRegExpStr = lessStrict(cwd.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
27+
const cwdRegExp = new RegExp(cwdRegExpStr, "g");
28+
const cwdSlashRegExp = new RegExp(cwdRegExpStr + "[\\/\\\\]", "g");
2829
webpack = lessStrict(webpack.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
2930
webpack = new RegExp(webpack, "g");
3031
webpackParent = lessStrict(webpackParent.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
@@ -33,7 +34,8 @@ exports.replaceBase = (template) => {
3334
return template
3435
.replace(/\r\n/g, "\n")
3536
.replace(/\r/g, "\n")
36-
.replace(cwd, ".")
37+
.replace(cwdSlashRegExp, "./")
38+
.replace(cwdRegExp, ".")
3739
.replace(webpack, "(webpack)")
3840
.replace(webpackParent, "(webpack)/~")
3941
.replace(timeRegexp, "")

0 commit comments

Comments
 (0)