Skip to content

Commit d4f4087

Browse files
authored
Merge pull request #104 from express-vue/feature/fix-windows-patch-bug
Feature/fix windows patch bug
2 parents 5e1a2d5 + adf5445 commit d4f4087

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"no-case": "^2.3.2",
8484
"pug": "^2.0.0-rc.4",
8585
"require-from-string": "^2.0.1",
86+
"slash": "^1.0.0",
8687
"string-hash": "^1.1.3",
8788
"vue": "^2.4.4",
8889
"vue-server-renderer": "^2.4.4",

src/utils/require.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @flow
22
const Module = require('module');
33
const path = require('path');
4+
const slash = require('slash');
45
const Utils = require('./index');
56
const Renderer = require('../renderer');
67
const Models = require('../models');
@@ -14,7 +15,7 @@ class Options {
1415
defaults: Models.Defaults;
1516
constructor(optsObj: Object) {
1617
this.vueFileRegex = /([\w/.\-@_\d]*\.vue)/igm;
17-
this.requireRegex = /(require\(['"])([\w/.\-@_\d]*\.vue)(['"]\))/igm;
18+
this.requireRegex = /(require\(['"])([\w:/.\-@_\d]*\.vue)(['"]\))/igm;
1819
this.appendPaths = optsObj.appendPaths || [];
1920
this.prependPaths = optsObj.prependPaths || [];
2021
this.rootPath = optsObj.rootPath || '';
@@ -59,25 +60,24 @@ function replaceRelativePaths(code: string, rootPath: string): string {
5960
const currentMatchesDouble = code.match(/(require\("\.\/)/gm);
6061
if (parentMatchesSingle) {
6162
for (const match of parentMatchesSingle) {
62-
code = code.replace(match, `require('${rootPath}/../`);
63+
code = code.replace(match, slash(`require('${rootPath}/../`));
6364
}
6465
}
6566
if (parentMatchesDouble) {
6667
for (const match of parentMatchesDouble) {
67-
code = code.replace(match, `require("${rootPath}/../`);
68+
code = code.replace(match, slash(`require("${rootPath}/../`));
6869
}
6970
}
7071
if (currentMatchesSingle) {
7172
for (const match of currentMatchesSingle) {
72-
code = code.replace(match, `require('${rootPath}/./`);
73+
code = code.replace(match, slash(`require('${rootPath}/./`));
7374
}
7475
}
7576
if (currentMatchesDouble) {
7677
for (const match of currentMatchesDouble) {
77-
code = code.replace(match, `require("${rootPath}/./`);
78+
code = code.replace(match, slash(`require("${rootPath}/./`));
7879
}
7980
}
80-
8181
return code;
8282
}
8383

tests/example/app.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const options = {
4040
}
4141
};
4242

43-
4443
renderer = expressVue.init(options);
4544

4645
const app = express();

0 commit comments

Comments
 (0)