@@ -562,7 +562,7 @@ impl ParserAndGenerator for AssetParserAndGenerator {
562
562
)
563
563
. await ?;
564
564
565
- let asset_path = if import_mode. is_preserve ( ) {
565
+ let asset_path = if import_mode. is_preserve ( ) || import_mode . is_new_url ( ) {
566
566
generate_context
567
567
. data
568
568
. insert ( CodeGenerationPublicPathAutoReplace ( true ) ) ;
@@ -631,37 +631,60 @@ impl ParserAndGenerator for AssetParserAndGenerator {
631
631
return Ok ( RawStringSource :: from ( "" ) . boxed ( ) ) ;
632
632
}
633
633
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 ) ;
639
672
return Ok (
640
673
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 ;"#
642
675
) )
643
676
. boxed ( ) ,
644
677
) ;
645
678
} else {
646
- let supports_const = compilation. options . output . environment . supports_const ( ) ;
647
- let declaration_kind = if supports_const { "const" } else { "var" } ;
648
679
return Ok (
649
680
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 ;"#
651
682
) )
652
683
. boxed ( ) ,
653
684
) ;
654
685
}
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
- ) ;
663
686
}
664
- } ;
687
+ }
665
688
666
689
if let Some ( ref mut scope) = generate_context. concatenation_scope {
667
690
scope. register_namespace_export ( NAMESPACE_OBJECT_EXPORT ) ;
0 commit comments