Skip to content

Commit 8453ef5

Browse files
committed
feat: export asset
1 parent de9c5ef commit 8453ef5

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

crates/node_binding/binding.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,7 @@ export interface RawAssetGeneratorOptions {
11281128
filename?: JsFilename
11291129
publicPath?: "auto" | JsFilename
11301130
dataUrl?: RawAssetGeneratorDataUrlOptions | ((arg: RawAssetGeneratorDataUrlFnArgs) => string)
1131+
experimentalLibReExport?: boolean
11311132
}
11321133

11331134
export interface RawAssetInlineGeneratorOptions {
@@ -1151,6 +1152,7 @@ export interface RawAssetResourceGeneratorOptions {
11511152
emit?: boolean
11521153
filename?: JsFilename
11531154
publicPath?: "auto" | JsFilename
1155+
experimentalLibReExport?: boolean
11541156
}
11551157

11561158
export interface RawBannerPluginOptions {

crates/rspack_binding_options/src/options/raw_module/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ pub struct RawAssetGeneratorOptions {
503503
ts_type = "RawAssetGeneratorDataUrlOptions | ((arg: RawAssetGeneratorDataUrlFnArgs) => string)"
504504
)]
505505
pub data_url: Option<RawAssetGeneratorDataUrl>,
506+
507+
pub __experimental_lib_re_export: Option<bool>,
506508
}
507509

508510
impl From<RawAssetGeneratorOptions> for AssetGeneratorOptions {
@@ -514,6 +516,7 @@ impl From<RawAssetGeneratorOptions> for AssetGeneratorOptions {
514516
data_url: value
515517
.data_url
516518
.map(|i| RawAssetGeneratorDataUrlWrapper(i).into()),
519+
__experimental_lib_re_export: value.__experimental_lib_re_export.map(|i| i.into()),
517520
}
518521
}
519522
}
@@ -545,6 +548,8 @@ pub struct RawAssetResourceGeneratorOptions {
545548
pub filename: Option<JsFilename>,
546549
#[napi(ts_type = "\"auto\" | JsFilename")]
547550
pub public_path: Option<JsFilename>,
551+
552+
pub __experimental_lib_re_export: Option<bool>,
548553
}
549554

550555
impl From<RawAssetResourceGeneratorOptions> for AssetResourceGeneratorOptions {
@@ -553,6 +558,7 @@ impl From<RawAssetResourceGeneratorOptions> for AssetResourceGeneratorOptions {
553558
emit: value.emit,
554559
filename: value.filename.map(|i| i.into()),
555560
public_path: value.public_path.map(|i| i.into()),
561+
__experimental_lib_re_export: value.__experimental_lib_re_export.map(|i| i.into()),
556562
}
557563
}
558564
}

crates/rspack_core/src/options/module.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,17 @@ impl GeneratorOptions {
357357
.and_then(|x| x.emit)
358358
.or_else(|| self.get_asset_resource().and_then(|x| x.emit))
359359
}
360+
361+
pub fn asset_experimental_lib_re_export(&self) -> Option<bool> {
362+
self
363+
.get_asset()
364+
.and_then(|x| x.__experimental_lib_re_export)
365+
.or_else(|| {
366+
self
367+
.get_asset_resource()
368+
.and_then(|x| x.__experimental_lib_re_export)
369+
})
370+
}
360371
}
361372

362373
#[cacheable]
@@ -371,6 +382,7 @@ pub struct AssetResourceGeneratorOptions {
371382
pub emit: Option<bool>,
372383
pub filename: Option<Filename>,
373384
pub public_path: Option<PublicPath>,
385+
pub __experimental_lib_re_export: Option<bool>,
374386
}
375387

376388
#[cacheable]
@@ -380,6 +392,7 @@ pub struct AssetGeneratorOptions {
380392
pub filename: Option<Filename>,
381393
pub public_path: Option<PublicPath>,
382394
pub data_url: Option<AssetGeneratorDataUrl>,
395+
pub __experimental_lib_re_export: Option<bool>,
383396
}
384397

385398
pub struct AssetGeneratorDataUrlFnArgs {

crates/rspack_plugin_asset/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ impl ParserAndGenerator for AssetParserAndGenerator {
452452
&source_file_name,
453453
)?;
454454

455+
dbg!(&module_generator_options);
456+
457+
let experimental_lib_re_export = module_generator_options
458+
.and_then(|x| x.asset_experimental_lib_re_export())
459+
.unwrap_or(false);
460+
455461
let asset_path = if let Some(public_path) =
456462
module_generator_options.and_then(|x| x.asset_public_path())
457463
{
@@ -621,6 +627,7 @@ async fn render_manifest(
621627
.get::<CodeGenerationDataAssetInfo>()
622628
.expect("should have asset_info")
623629
.inner();
630+
dbg!(&asset_filename, &asset_info);
624631
RenderManifestEntry {
625632
source: source.clone(),
626633
filename: asset_filename.to_owned(),

crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ impl ModuleConcatenationPlugin {
555555
let box_module = module_graph
556556
.module_by_identifier(&root_module_id)
557557
.expect("should have module");
558+
let root_module_source_types = box_module.source_types().clone();
559+
let is_root_module_asset_module = root_module_source_types.contains(&SourceType::Asset);
560+
558561
let root_module_ctxt = RootModuleContext {
559562
id: root_module_id,
560563
readable_identifier: box_module
@@ -677,8 +680,26 @@ impl ModuleConcatenationPlugin {
677680
// .module_identifier_to_module
678681
// .remove(&root_module_id);
679682
// compilation.chunk_graph.clear
683+
if is_root_module_asset_module {
684+
chunk_graph.replace_module(&root_module_id, &new_module.id());
685+
chunk_graph.add_module(root_module_id);
686+
for chunk_ukey in chunk_graph.get_module_chunks(new_module.id()).clone() {
687+
let module = module_graph
688+
.module_by_identifier(&root_module_id)
689+
.expect("should exist module");
680690

681-
chunk_graph.replace_module(&root_module_id, &new_module.id());
691+
let source_types = chunk_graph.get_chunk_module_source_types(&chunk_ukey, module);
692+
let new_source_types = source_types
693+
.iter()
694+
.filter(|source_type| !matches!(source_type, SourceType::JavaScript))
695+
.copied()
696+
.collect();
697+
chunk_graph.set_chunk_modules_source_types(&chunk_ukey, root_module_id, new_source_types);
698+
chunk_graph.connect_chunk_and_module(chunk_ukey, root_module_id);
699+
}
700+
} else {
701+
chunk_graph.replace_module(&root_module_id, &new_module.id());
702+
}
682703

683704
module_graph.move_module_connections(&root_module_id, &new_module.id(), |c, dep| {
684705
let other_module = if *c.module_identifier() == root_module_id {

0 commit comments

Comments
 (0)