11// @flow
22const Module = require ( 'module' ) ;
33const path = require ( 'path' ) ;
4+ const slash = require ( 'slash' ) ;
45const Utils = require ( './index' ) ;
56const Renderer = require ( '../renderer' ) ;
67const Models = require ( '../models' ) ;
@@ -14,7 +15,7 @@ class Options {
1415 defaults : Models . Defaults ;
1516 constructor ( optsObj : Object ) {
1617 this . vueFileRegex = / ( [ \w / . \- @ _ \d ] * \. v u e ) / igm;
17- this . requireRegex = / ( r e q u i r e \( [ ' " ] ) ( [ \w / . \- @ _ \d ] * \. v u e ) ( [ ' " ] \) ) / igm;
18+ this . requireRegex = / ( r e q u i r e \( [ ' " ] ) ( [ \w : / . \- @ _ \d ] * \. v u e ) ( [ ' " ] \) ) / 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 ( / ( r e q u i r e \( " \. \/ ) / 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
0 commit comments