Skip to content

Commit fd7e9bc

Browse files
committed
fixed the windows require file problems
1 parent 1e4de22 commit fd7e9bc

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/utils/require.js

Lines changed: 6 additions & 5 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');
@@ -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

@@ -131,6 +131,7 @@ function requireFromString(code: string, filename: string = '', optsObj: Object
131131
reject(error);
132132
});
133133
} else {
134+
console.log(code)
134135
m._compile(code, filename);
135136
resolve(m.exports.default);
136137
}

tests/example/app.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
const path = require('path');
33
const express = require('express');
44
const uuidv4 = require('uuid/v4');
5-
const slash = require('slash');
65

76
const expressVueRenderer = require('../../lib');
87
const expressVue = require('./expressVue');
@@ -16,7 +15,7 @@ var exampleMixin = {
1615
};
1716

1817
const options = {
19-
rootPath: slash(path.join(__dirname, 'vueFiles')),
18+
rootPath: path.join(__dirname, 'vueFiles'),
2019
vue: {
2120
head: {
2221
meta: [{
@@ -41,7 +40,6 @@ const options = {
4140
}
4241
};
4342

44-
4543
renderer = expressVue.init(options);
4644

4745
const app = express();

0 commit comments

Comments
 (0)