22 MIT License http://www.opensource.org/licenses/mit-license.php
33 Author Tobias Koppers @sokra
44*/
5+ var path = require ( "path" ) ;
56var Module = require ( "./Module" ) ;
67var OriginalSource = require ( "webpack-sources" ) . OriginalSource ;
78var RawSource = require ( "webpack-sources" ) . RawSource ;
@@ -56,6 +57,30 @@ ContextModule.prototype.readableIdentifier = function(requestShortener) {
5657 return identifier . replace ( / $ / , "" ) ;
5758} ;
5859
60+ function contextify ( options , request ) {
61+ return request . split ( "!" ) . map ( function ( r ) {
62+ var rp = path . relative ( options . context , r ) ;
63+ if ( path . sep === "\\" )
64+ rp = rp . replace ( / \\ / g, "/" ) ;
65+ if ( rp . indexOf ( "../" ) !== 0 )
66+ rp = "./" + rp ;
67+ return rp ;
68+ } ) . join ( "!" ) ;
69+ }
70+
71+ ContextModule . prototype . libIdent = function ( options ) {
72+ var identifier = contextify ( options , this . context ) + " " ;
73+ if ( this . async )
74+ identifier += "async " ;
75+ if ( this . recursive )
76+ identifier += "recursive " ;
77+ if ( this . addon )
78+ identifier += contextify ( options , this . addon ) ;
79+ if ( this . regExp )
80+ identifier += prettyRegExp ( this . regExp + "" )
81+ return identifier . replace ( / $ / , "" ) ;
82+ } ;
83+
5984ContextModule . prototype . needRebuild = function ( fileTimestamps , contextTimestamps ) {
6085 var ts = contextTimestamps [ this . context ] ;
6186 if ( ! ts ) return true ;
@@ -121,7 +146,7 @@ ContextModule.prototype.source = function() {
121146 "};\n" ,
122147 "webpackContext.resolve = webpackContextResolve;\n" ,
123148 "module.exports = webpackContext;\n" ,
124- "webpackContext.id = " + this . id + ";\n"
149+ "webpackContext.id = " + JSON . stringify ( this . id ) + ";\n"
125150 ] ;
126151 } else if ( this . blocks && this . blocks . length > 0 ) {
127152 var items = this . blocks . map ( function ( block ) {
@@ -165,7 +190,7 @@ ContextModule.prototype.source = function() {
165190 "\treturn Object.keys(map);\n" ,
166191 "};\n" ,
167192 "module.exports = webpackAsyncContext;\n" ,
168- "webpackAsyncContext.id = " + this . id + ";\n"
193+ "webpackAsyncContext.id = " + JSON . stringify ( this . id ) + ";\n"
169194 ] ;
170195 } else {
171196 str = [
@@ -175,7 +200,7 @@ ContextModule.prototype.source = function() {
175200 "webpackEmptyContext.keys = function() { return []; };\n" ,
176201 "webpackEmptyContext.resolve = webpackEmptyContext;\n" ,
177202 "module.exports = webpackEmptyContext;\n" ,
178- "webpackEmptyContext.id = " + this . id + ";\n"
203+ "webpackEmptyContext.id = " + JSON . stringify ( this . id ) + ";\n"
179204 ] ;
180205 }
181206 if ( this . useSourceMap ) {
0 commit comments