1+ /*
2+ MIT License http://www.opensource.org/licenses/mit-license.php
3+ Author Tobias Koppers @sokra
4+ */
5+ var RawSource = require ( "webpack-core/lib/RawSource" ) ;
6+ var base64Encode = require ( "base64-encode" ) ;
7+
8+ function EvalSourceMapDevToolModuleTemplateDecorator ( compilation , moduleTemplate , sourceMapComment ) {
9+ this . compilation = compilation ;
10+ this . moduleTemplate = moduleTemplate ;
11+ this . sourceMapComment = sourceMapComment || "//@ sourceMappingURL=[url]" ;
12+ }
13+ module . exports = EvalSourceMapDevToolModuleTemplateDecorator ;
14+
15+ EvalSourceMapDevToolModuleTemplateDecorator . prototype . render = function ( module , dependencyTemplates ) {
16+ var compilation = this . compilation ;
17+ var sourceMapComment = this . sourceMapComment ;
18+ var fakeModule = {
19+ source : function ( dependencyTemplates , outputOptions , requestShortener ) {
20+ var source = module . source ( dependencyTemplates , outputOptions , requestShortener ) ;
21+ var content = source . source ( ) ;
22+ var sourceMap = source . map ( ) ;
23+ if ( ! sourceMap ) {
24+ return source ;
25+ }
26+ for ( var i = 0 ; i < sourceMap . sources . length ; i ++ ) {
27+ var source = sourceMap . sources [ i ] ;
28+ var str ;
29+ var m = compilation . findModule ( source ) ;
30+ if ( m )
31+ str = m . readableIdentifier ( requestShortener ) ;
32+ else
33+ str = requestShortener . shorten ( source ) ;
34+ str = str . split ( "!" ) ;
35+ str = str . pop ( ) + ( str . length > 0 ? " " + str . join ( "!" ) : "" ) ;
36+ var idx ;
37+ while ( ( idx = sourceMap . sources . indexOf ( str ) >= 0 ) && ( idx < i ) ) {
38+ str += "*" ;
39+ }
40+ sourceMap . sources [ i ] = str ;
41+ }
42+ sourceMap . sourceRoot = "webpack-module://" ;
43+ var footer = sourceMapComment . replace ( / \[ u r l \] / g, "data:application/json;base64," + base64Encode ( JSON . stringify ( sourceMap ) ) ) ;
44+ return new RawSource ( "eval(" + JSON . stringify ( content + footer ) + ");" ) ;
45+ } ,
46+ identifier : function ( ) { return module . identifier ( ) } ,
47+ readableIdentifier : function ( rs ) { return module . readableIdentifier ( rs ) } ,
48+ id : module . id
49+ } ;
50+ return this . moduleTemplate . render ( fakeModule , dependencyTemplates ) ;
51+ } ;
52+
53+ EvalSourceMapDevToolModuleTemplateDecorator . prototype . updateHash = function ( hash ) {
54+ hash . update ( "eval-source-map" ) ;
55+ hash . update ( "1" ) ;
56+ } ;
0 commit comments