@@ -267,7 +267,10 @@ class RolldownEnvironment extends DevEnvironment {
267267 if ( this . name === 'client' ) {
268268 ctx . server . ws . send ( 'rolldown:hmr' , result )
269269 } else {
270- this . getRunner ( ) . evaluate ( result [ 1 ] . toString ( ) )
270+ this . getRunner ( ) . evaluate (
271+ result [ 1 ] . toString ( ) ,
272+ path . join ( this . outDir , result [ 0 ] ) ,
273+ )
271274 }
272275 console . timeEnd ( `[rolldown:${ this . name } :hmr]` )
273276 } else {
@@ -286,7 +289,7 @@ class RolldownEnvironment extends DevEnvironment {
286289 const filepath = path . join ( this . outDir , output . fileName )
287290 this . runner = new RolldownModuleRunner ( )
288291 const code = fs . readFileSync ( filepath , 'utf-8' )
289- this . runner . evaluate ( code )
292+ this . runner . evaluate ( code , filepath )
290293 }
291294 return this . runner
292295 }
@@ -323,13 +326,12 @@ class RolldownModuleRunner {
323326 return mod . exports
324327 }
325328
326- evaluate ( code : string ) {
329+ evaluate ( code : string , sourceURL : string ) {
327330 const context = {
328331 self : this . context ,
329332 ...this . context ,
330333 }
331- // TODO: sourcemap not working?
332- // extract sourcemap
334+ // extract sourcemap and move to the bottom
333335 const sourcemap = code . match ( / ^ \/ \/ # s o u r c e M a p p i n g U R L = .* / m) ?. [ 0 ] ?? ''
334336 if ( sourcemap ) {
335337 code = code . replace ( sourcemap , '' )
@@ -341,6 +343,7 @@ self.__toCommonJS = __toCommonJS;
341343self.__export = __export;
342344self.__toESM = __toESM;
343345}}
346+ //# sourceURL=${ sourceURL }
344347//# sourceMappingSource=rolldown-module-runner
345348${ sourcemap }
346349`
0 commit comments