File tree Expand file tree Collapse file tree
integration/sourcemap-reference Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -205,13 +205,16 @@ class JSPackager extends Packager {
205205
206206 await this . write ( '},{},' + JSON . stringify ( entry ) + ')' ) ;
207207 if ( this . options . sourceMaps ) {
208- // Add source map url
209- await this . write (
210- `\n//# sourceMappingURL=${ urlJoin (
211- this . options . publicURL ,
212- path . basename ( this . bundle . name , '.js' ) + '.map'
213- ) } `
214- ) ;
208+ // Add source map url if a map bundle exists
209+ let mapBundle = this . bundle . siblingBundlesMap . get ( 'map' ) ;
210+ if ( mapBundle ) {
211+ await this . write (
212+ `\n//# sourceMappingURL=${ urlJoin (
213+ this . options . publicURL ,
214+ path . basename ( mapBundle . name )
215+ ) } `
216+ ) ;
217+ }
215218 }
216219 await this . dest . end ( ) ;
217220 }
Original file line number Diff line number Diff line change 1+ {
2+ "some" : " data" ,
3+ "more" : {
4+ "data" : " value"
5+ }
6+ }
Original file line number Diff line number Diff line change 1+ < html >
2+ < head >
3+ < script src ="./index.js "> </ script >
4+ </ head >
5+ < body >
6+ Hello!
7+ </ body >
8+ </ html >
Original file line number Diff line number Diff line change 1+ import './data.json' ;
Original file line number Diff line number Diff line change @@ -148,4 +148,43 @@ describe('sourcemaps', function() {
148148 assert . equal ( typeof output , 'function' ) ;
149149 assert . equal ( output ( ) , 14 ) ;
150150 } ) ;
151+
152+ it ( 'should create a valid sourcemap reference for a child bundle' , async function ( ) {
153+ let b = await bundle (
154+ __dirname + '/integration/sourcemap-reference/index.html'
155+ ) ;
156+
157+ assertBundleTree ( b , {
158+ name : 'index.html' ,
159+ assets : [ 'index.html' ] ,
160+ childBundles : [
161+ {
162+ type : 'js' ,
163+ assets : [ 'index.js' , 'data.json' ] ,
164+ childBundles : [
165+ {
166+ type : 'map'
167+ }
168+ ]
169+ }
170+ ]
171+ } ) ;
172+
173+ let jsOutput = fs
174+ . readFileSync ( Array . from ( b . childBundles ) [ 0 ] . name )
175+ . toString ( ) ;
176+
177+ let sourcemapReference = path . join (
178+ __dirname ,
179+ '/dist/' ,
180+ jsOutput . substring ( jsOutput . lastIndexOf ( '//# sourceMappingURL' ) + 22 )
181+ ) ;
182+ assert (
183+ fs . existsSync ( path . join ( sourcemapReference ) ) ,
184+ 'referenced sourcemap should exist'
185+ ) ;
186+
187+ let map = fs . readFileSync ( path . join ( sourcemapReference ) ) . toString ( ) ;
188+ mapValidator ( jsOutput , map ) ;
189+ } ) ;
151190} ) ;
You can’t perform that action at this time.
0 commit comments