@@ -426,13 +426,13 @@ impl ParserAndGenerator for AssetParserAndGenerator {
426426 . as_normal_module ( )
427427 . expect ( "module should be a NormalModule in AssetParserAndGenerator" ) ;
428428 let module_generator_options = normal_module. get_generator_options ( ) ;
429+ dbg ! ( module_generator_options) ;
429430
430431 let result = match generate_context. requested_source_type {
431432 SourceType :: JavaScript => {
432433 let exported_content = if parsed_asset_config. is_inline ( ) {
433434 let resource_data: & ResourceData = normal_module. resource_resolved_data ( ) ;
434435 let data_url = module_generator_options. and_then ( |x| x. asset_data_url ( ) ) ;
435-
436436 let encoded_source: String ;
437437
438438 if let Some ( custom_data_url) =
@@ -522,6 +522,61 @@ impl ParserAndGenerator for AssetParserAndGenerator {
522522 } else {
523523 unreachable ! ( )
524524 } ;
525+
526+ let experimental_lib_preserve_import = module_generator_options
527+ . and_then ( |x| x. get_asset ( ) )
528+ . and_then ( |x| x. experimental_lib_preserve_import )
529+ . or_else ( || {
530+ module_generator_options
531+ . and_then ( |x| x. get_asset_resource ( ) )
532+ . and_then ( |x| x. experimental_lib_preserve_import )
533+ } )
534+ . unwrap_or ( false ) ;
535+ let experimental_lib_re_export = module_generator_options
536+ . and_then ( |x| x. get_asset ( ) )
537+ . and_then ( |x| x. experimental_lib_re_export )
538+ . or_else ( || {
539+ module_generator_options
540+ . and_then ( |x| x. get_asset_resource ( ) )
541+ . and_then ( |x| x. experimental_lib_re_export )
542+ } )
543+ . unwrap_or ( false ) ;
544+
545+ dbg ! ( experimental_lib_preserve_import, experimental_lib_re_export) ;
546+
547+ if experimental_lib_preserve_import || experimental_lib_re_export {
548+ let Some ( PublicPath :: Auto ) = module_generator_options. and_then ( |x| x. asset_public_path ( ) )
549+ else {
550+ return Err ( error ! (
551+ "`experimentalLibPreserveImport` and `experimentalLibReExport` can only be used with `asset/resource` and `publicPath: 'auto'`"
552+ ) ) ;
553+ } ;
554+
555+ if let Some ( ref mut scope) = generate_context. concatenation_scope {
556+ scope. register_namespace_export ( NAMESPACE_OBJECT_EXPORT ) ;
557+ return Ok ( if experimental_lib_re_export {
558+ RawStringSource :: from ( format ! (
559+ r#"import {NAMESPACE_OBJECT_EXPORT} from {exported_content};
560+ export default {NAMESPACE_OBJECT_EXPORT};"#
561+ ) )
562+ . boxed ( )
563+ } else {
564+ RawStringSource :: from ( format ! (
565+ r#"import {NAMESPACE_OBJECT_EXPORT} from {exported_content};"#
566+ ) )
567+ . boxed ( )
568+ } ) ;
569+ } else {
570+ generate_context
571+ . runtime_requirements
572+ . insert ( RuntimeGlobals :: MODULE ) ;
573+ return Ok (
574+ RawStringSource :: from ( format ! ( r#"module.exports = require({exported_content})"# ) )
575+ . boxed ( ) ,
576+ ) ;
577+ }
578+ }
579+
525580 if let Some ( ref mut scope) = generate_context. concatenation_scope {
526581 scope. register_namespace_export ( NAMESPACE_OBJECT_EXPORT ) ;
527582 let supports_const = compilation. options . output . environment . supports_const ( ) ;
@@ -646,6 +701,7 @@ async fn render_manifest(
646701 . get :: < CodeGenerationDataAssetInfo > ( )
647702 . expect ( "should have asset_info" )
648703 . inner ( ) ;
704+ dbg ! ( & asset_filename, & asset_info) ;
649705 RenderManifestEntry {
650706 source : source. clone ( ) ,
651707 filename : asset_filename. to_owned ( ) ,
0 commit comments