@@ -562,7 +562,7 @@ impl ParserAndGenerator for AssetParserAndGenerator {
562562            ) 
563563            . await ?; 
564564
565-           let  asset_path = if  import_mode. is_preserve ( )  { 
565+           let  asset_path = if  import_mode. is_preserve ( )  || import_mode . is_new_url ( )   { 
566566            generate_context
567567              . data 
568568              . insert ( CodeGenerationPublicPathAutoReplace ( true ) ) ; 
@@ -631,37 +631,60 @@ impl ParserAndGenerator for AssetParserAndGenerator {
631631          return  Ok ( RawStringSource :: from ( "" ) . boxed ( ) ) ; 
632632        } 
633633
634-         if  import_mode. is_preserve ( )  && parsed_asset_config. is_resource ( )  { 
635-           let  is_module = compilation. options . output . module ; 
636-           if  let  Some ( ref  mut  scope)  = generate_context. concatenation_scope  { 
637-             scope. register_namespace_export ( NAMESPACE_OBJECT_EXPORT ) ; 
638-             if  is_module { 
634+         if  parsed_asset_config. is_resource ( )  { 
635+           if  import_mode. is_preserve ( )  { 
636+             let  is_module = compilation. options . output . module ; 
637+             if  let  Some ( ref  mut  scope)  = generate_context. concatenation_scope  { 
638+               scope. register_namespace_export ( NAMESPACE_OBJECT_EXPORT ) ; 
639+               if  is_module { 
640+                 return  Ok ( 
641+                   RawStringSource :: from ( format ! ( 
642+                     r#"import {NAMESPACE_OBJECT_EXPORT} from {exported_content};"# 
643+                   ) ) 
644+                   . boxed ( ) , 
645+                 ) ; 
646+               }  else  { 
647+                 let  supports_const = compilation. options . output . environment . supports_const ( ) ; 
648+                 let  declaration_kind = if  supports_const {  "const"  }  else  {  "var"  } ; 
649+                 return  Ok ( 
650+                   RawStringSource :: from ( format ! ( 
651+                     r#"{declaration_kind} {NAMESPACE_OBJECT_EXPORT} = require({exported_content});"# 
652+                   ) ) 
653+                   . boxed ( ) , 
654+                 ) ; 
655+               } 
656+             }  else  { 
657+               generate_context
658+                 . runtime_requirements 
659+                 . insert ( RuntimeGlobals :: MODULE ) ; 
660+               return  Ok ( 
661+                 RawStringSource :: from ( format ! ( r#"module.exports = require({exported_content});"# ) ) 
662+                   . boxed ( ) , 
663+               ) ; 
664+             } 
665+           } ; 
666+ 
667+           if  import_mode. is_new_url ( )  { 
668+             if  let  Some ( ref  mut  scope)  = generate_context. concatenation_scope  { 
669+               let  supports_const = compilation. options . output . environment . supports_const ( ) ; 
670+               let  declaration_kind = if  supports_const {  "const"  }  else  {  "var"  } ; 
671+               scope. register_namespace_export ( NAMESPACE_OBJECT_EXPORT ) ; 
639672              return  Ok ( 
640673                RawStringSource :: from ( format ! ( 
641-                   r#"import  {NAMESPACE_OBJECT_EXPORT} from  {exported_content};"# 
674+                   r#"{declaration_kind}  {NAMESPACE_OBJECT_EXPORT} = /*#__PURE__*/ new URL( {exported_content}, import.meta.url).href ;"# 
642675                ) ) 
643676                . boxed ( ) , 
644677              ) ; 
645678            }  else  { 
646-               let  supports_const = compilation. options . output . environment . supports_const ( ) ; 
647-               let  declaration_kind = if  supports_const {  "const"  }  else  {  "var"  } ; 
648679              return  Ok ( 
649680                RawStringSource :: from ( format ! ( 
650-                   r#"{declaration_kind} {NAMESPACE_OBJECT_EXPORT} = require ({exported_content}) ;"# 
681+                   r#"module.exports = /*#__PURE__*/ new URL ({exported_content}, import.meta.url).href ;"# 
651682                ) ) 
652683                . boxed ( ) , 
653684              ) ; 
654685            } 
655-           }  else  { 
656-             generate_context
657-               . runtime_requirements 
658-               . insert ( RuntimeGlobals :: MODULE ) ; 
659-             return  Ok ( 
660-               RawStringSource :: from ( format ! ( r#"module.exports = require({exported_content});"# ) ) 
661-                 . boxed ( ) , 
662-             ) ; 
663686          } 
664-         } ; 
687+         } 
665688
666689        if  let  Some ( ref  mut  scope)  = generate_context. concatenation_scope  { 
667690          scope. register_namespace_export ( NAMESPACE_OBJECT_EXPORT ) ; 
0 commit comments