@@ -25,6 +25,11 @@ NodeSourcePlugin.prototype.apply = function(compiler) {
2525 return require . resolve ( "node-libs-browser/mock/empty" ) ;
2626 } else return module ;
2727 }
28+
29+ function getStringOfRelativePath ( context , pathToModule ) {
30+ return JSON . stringify ( path . relative ( context , pathToModule ) . replace ( / \\ / g, '/' ) )
31+ }
32+
2833 compiler . plugin ( "compilation" , function ( compilation , params ) {
2934 params . normalModuleFactory . plugin ( "parser" , function ( parser , parserOptions ) {
3035
@@ -39,38 +44,35 @@ NodeSourcePlugin.prototype.apply = function(compiler) {
3944 var processType = localOptions . process ;
4045 parser . plugin ( "expression process" , function ( ) {
4146 return ModuleParserHelpers . addParsedVariable ( this , "process" , "require(" +
42- JSON . stringify ( path . relative ( this . state . module . context , getPathToModule ( "process" , processType ) ) ) + ")" ) ;
47+ getStringOfRelativePath ( this . state . module . context , getPathToModule ( "process" , processType ) ) + ")" ) ;
4348 } ) ;
4449 }
4550 if ( localOptions . global ) {
4651 parser . plugin ( "expression global" , function ( ) {
4752 return ModuleParserHelpers . addParsedVariable ( this , "global" , "require(" +
48- JSON . stringify ( path . relative ( this . state . module . context , require . resolve ( "../../buildin/global.js" ) ) ) + ")" ) ;
53+ getStringOfRelativePath ( this . state . module . context , require . resolve ( "../../buildin/global.js" ) ) + ")" ) ;
4954 } ) ;
5055 }
5156 if ( localOptions . console ) {
5257 var consoleType = localOptions . console ;
5358 parser . plugin ( "expression console" , function ( ) {
5459 return ModuleParserHelpers . addParsedVariable ( this , "console" , "require(" +
55- JSON . stringify ( path . relative ( this . state . module . context , getPathToModule ( "console" , consoleType ) ) ) + ")" ) ;
60+ getStringOfRelativePath ( this . state . module . context , getPathToModule ( "console" , consoleType ) ) + ")" ) ;
5661 } ) ;
5762 }
5863 var bufferType = localOptions . Buffer ;
5964 if ( bufferType ) {
6065 parser . plugin ( "expression Buffer" , function ( ) {
61- return ModuleParserHelpers . addParsedVariable ( this , "Buffer" , "require(" +
62- JSON . stringify ( path . relative ( this . state . module . context , getPathToModule ( "buffer" , bufferType ) ) ) + ").Buffer" ) ;
66+ return ModuleParserHelpers . addParsedVariable ( this , "Buffer" , "require(" + JSON . stringify ( getPathToModule ( "buffer" , bufferType ) ) + ").Buffer" ) ;
6367 } ) ;
6468 }
6569 if ( localOptions . setImmediate ) {
6670 var setImmediateType = localOptions . setImmediate ;
6771 parser . plugin ( "expression setImmediate" , function ( ) {
68- return ModuleParserHelpers . addParsedVariable ( this , "setImmediate" , "require(" +
69- JSON . stringify ( path . relative ( this . state . module . context , getPathToModule ( "timers" , setImmediateType ) ) ) + ").setImmediate" ) ;
72+ return ModuleParserHelpers . addParsedVariable ( this , "setImmediate" , "require(" + JSON . stringify ( getPathToModule ( "timers" , setImmediateType ) ) + ").setImmediate" ) ;
7073 } ) ;
7174 parser . plugin ( "expression clearImmediate" , function ( ) {
72- return ModuleParserHelpers . addParsedVariable ( this , "clearImmediate" , "require(" +
73- JSON . stringify ( path . relative ( this . state . module . context , getPathToModule ( "timers" , setImmediateType ) ) ) + ").clearImmediate" ) ;
75+ return ModuleParserHelpers . addParsedVariable ( this , "clearImmediate" , "require(" + JSON . stringify ( getPathToModule ( "timers" , setImmediateType ) ) + ").clearImmediate" ) ;
7476 } ) ;
7577 }
7678 } ) ;
0 commit comments