diff --git a/package.json b/package.json index 6a50ee8..97e97d3 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "no-case": "^2.3.2", "pug": "^2.0.0-rc.4", "require-from-string": "^2.0.1", + "slash": "^1.0.0", "string-hash": "^1.1.3", "vue": "^2.4.4", "vue-server-renderer": "^2.4.4", diff --git a/src/utils/require.js b/src/utils/require.js index 6e1c5d5..2539675 100644 --- a/src/utils/require.js +++ b/src/utils/require.js @@ -1,6 +1,7 @@ // @flow const Module = require('module'); const path = require('path'); +const slash = require('slash'); const Utils = require('./index'); const Renderer = require('../renderer'); const Models = require('../models'); @@ -14,7 +15,7 @@ class Options { defaults: Models.Defaults; constructor(optsObj: Object) { this.vueFileRegex = /([\w/.\-@_\d]*\.vue)/igm; - this.requireRegex = /(require\(['"])([\w/.\-@_\d]*\.vue)(['"]\))/igm; + this.requireRegex = /(require\(['"])([\w:/.\-@_\d]*\.vue)(['"]\))/igm; this.appendPaths = optsObj.appendPaths || []; this.prependPaths = optsObj.prependPaths || []; this.rootPath = optsObj.rootPath || ''; @@ -59,25 +60,24 @@ function replaceRelativePaths(code: string, rootPath: string): string { const currentMatchesDouble = code.match(/(require\("\.\/)/gm); if (parentMatchesSingle) { for (const match of parentMatchesSingle) { - code = code.replace(match, `require('${rootPath}/../`); + code = code.replace(match, slash(`require('${rootPath}/../`)); } } if (parentMatchesDouble) { for (const match of parentMatchesDouble) { - code = code.replace(match, `require("${rootPath}/../`); + code = code.replace(match, slash(`require("${rootPath}/../`)); } } if (currentMatchesSingle) { for (const match of currentMatchesSingle) { - code = code.replace(match, `require('${rootPath}/./`); + code = code.replace(match, slash(`require('${rootPath}/./`)); } } if (currentMatchesDouble) { for (const match of currentMatchesDouble) { - code = code.replace(match, `require("${rootPath}/./`); + code = code.replace(match, slash(`require("${rootPath}/./`)); } } - return code; } diff --git a/tests/example/app.js b/tests/example/app.js index 0348843..0d30e25 100644 --- a/tests/example/app.js +++ b/tests/example/app.js @@ -40,7 +40,6 @@ const options = { } }; - renderer = expressVue.init(options); const app = express();