@@ -409,13 +409,13 @@ impl ParserAndGenerator for AssetParserAndGenerator {
409409 . as_normal_module ( )
410410 . expect ( "module should be a NormalModule in AssetParserAndGenerator" ) ;
411411 let module_generator_options = normal_module. get_generator_options ( ) ;
412+ dbg ! ( module_generator_options) ;
412413
413414 let result = match generate_context. requested_source_type {
414415 SourceType :: JavaScript => {
415416 let exported_content = if parsed_asset_config. is_inline ( ) {
416417 let resource_data: & ResourceData = normal_module. resource_resolved_data ( ) ;
417418 let data_url = module_generator_options. and_then ( |x| x. asset_data_url ( ) ) ;
418-
419419 let encoded_source: String ;
420420
421421 if let Some ( custom_data_url) = self . get_data_url ( resource_data, data_url, source) {
@@ -498,6 +498,61 @@ impl ParserAndGenerator for AssetParserAndGenerator {
498498 } else {
499499 unreachable ! ( )
500500 } ;
501+
502+ let experimental_lib_preserve_import = module_generator_options
503+ . and_then ( |x| x. get_asset ( ) )
504+ . and_then ( |x| x. experimental_lib_preserve_import )
505+ . or_else ( || {
506+ module_generator_options
507+ . and_then ( |x| x. get_asset_resource ( ) )
508+ . and_then ( |x| x. experimental_lib_preserve_import )
509+ } )
510+ . unwrap_or ( false ) ;
511+ let experimental_lib_re_export = module_generator_options
512+ . and_then ( |x| x. get_asset ( ) )
513+ . and_then ( |x| x. experimental_lib_re_export )
514+ . or_else ( || {
515+ module_generator_options
516+ . and_then ( |x| x. get_asset_resource ( ) )
517+ . and_then ( |x| x. experimental_lib_re_export )
518+ } )
519+ . unwrap_or ( false ) ;
520+
521+ dbg ! ( experimental_lib_preserve_import, experimental_lib_re_export) ;
522+
523+ if experimental_lib_preserve_import || experimental_lib_re_export {
524+ let Some ( PublicPath :: Auto ) = module_generator_options. and_then ( |x| x. asset_public_path ( ) )
525+ else {
526+ return Err ( error ! (
527+ "`experimentalLibPreserveImport` and `experimentalLibReExport` can only be used with `asset/resource` and `publicPath: 'auto'`"
528+ ) ) ;
529+ } ;
530+
531+ if let Some ( ref mut scope) = generate_context. concatenation_scope {
532+ scope. register_namespace_export ( NAMESPACE_OBJECT_EXPORT ) ;
533+ return Ok ( if experimental_lib_re_export {
534+ RawStringSource :: from ( format ! (
535+ r#"import {NAMESPACE_OBJECT_EXPORT} from {exported_content};
536+ export default {NAMESPACE_OBJECT_EXPORT};"#
537+ ) )
538+ . boxed ( )
539+ } else {
540+ RawStringSource :: from ( format ! (
541+ r#"import {NAMESPACE_OBJECT_EXPORT} from {exported_content};"#
542+ ) )
543+ . boxed ( )
544+ } ) ;
545+ } else {
546+ generate_context
547+ . runtime_requirements
548+ . insert ( RuntimeGlobals :: MODULE ) ;
549+ return Ok (
550+ RawStringSource :: from ( format ! ( r#"module.exports = require({exported_content})"# ) )
551+ . boxed ( ) ,
552+ ) ;
553+ }
554+ }
555+
501556 if let Some ( ref mut scope) = generate_context. concatenation_scope {
502557 scope. register_namespace_export ( NAMESPACE_OBJECT_EXPORT ) ;
503558 let supports_const = compilation. options . output . environment . supports_const ( ) ;
@@ -621,6 +676,7 @@ async fn render_manifest(
621676 . get :: < CodeGenerationDataAssetInfo > ( )
622677 . expect ( "should have asset_info" )
623678 . inner ( ) ;
679+ dbg ! ( & asset_filename, & asset_info) ;
624680 RenderManifestEntry {
625681 source : source. clone ( ) ,
626682 filename : asset_filename. to_owned ( ) ,
0 commit comments