@@ -267,7 +267,10 @@ class RolldownEnvironment extends DevEnvironment {
267
267
if ( this . name === 'client' ) {
268
268
ctx . server . ws . send ( 'rolldown:hmr' , result )
269
269
} else {
270
- this . getRunner ( ) . evaluate ( result [ 1 ] . toString ( ) )
270
+ this . getRunner ( ) . evaluate (
271
+ result [ 1 ] . toString ( ) ,
272
+ path . join ( this . outDir , result [ 0 ] ) ,
273
+ )
271
274
}
272
275
console . timeEnd ( `[rolldown:${ this . name } :hmr]` )
273
276
} else {
@@ -286,7 +289,7 @@ class RolldownEnvironment extends DevEnvironment {
286
289
const filepath = path . join ( this . outDir , output . fileName )
287
290
this . runner = new RolldownModuleRunner ( )
288
291
const code = fs . readFileSync ( filepath , 'utf-8' )
289
- this . runner . evaluate ( code )
292
+ this . runner . evaluate ( code , filepath )
290
293
}
291
294
return this . runner
292
295
}
@@ -323,13 +326,12 @@ class RolldownModuleRunner {
323
326
return mod . exports
324
327
}
325
328
326
- evaluate ( code : string ) {
329
+ evaluate ( code : string , sourceURL : string ) {
327
330
const context = {
328
331
self : this . context ,
329
332
...this . context ,
330
333
}
331
- // TODO: sourcemap not working?
332
- // extract sourcemap
334
+ // extract sourcemap and move to the bottom
333
335
const sourcemap = code . match ( / ^ \/ \/ # s o u r c e M a p p i n g U R L = .* / m) ?. [ 0 ] ?? ''
334
336
if ( sourcemap ) {
335
337
code = code . replace ( sourcemap , '' )
@@ -341,6 +343,7 @@ self.__toCommonJS = __toCommonJS;
341
343
self.__export = __export;
342
344
self.__toESM = __toESM;
343
345
}}
346
+ //# sourceURL=${ sourceURL }
344
347
//# sourceMappingSource=rolldown-module-runner
345
348
${ sourcemap }
346
349
`
0 commit comments