-
-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support
experiments.outputModule
(#2803)
* feat: output module * fix: format * fix: test * fix: test * fix: test * fix: avoid add tree_shaking_result * fix: test * fix: test * fix: test * fix: test
- Loading branch information
1 parent
227a0ed
commit 62628a0
Showing
47 changed files
with
1,644 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::hash::Hash; | ||
|
||
use rspack_core::{ | ||
rspack_sources::{ConcatSource, RawSource, SourceExt}, | ||
to_identifier, JsChunkHashArgs, Plugin, PluginContext, PluginJsChunkHashHookOutput, | ||
PluginRenderStartupHookOutput, RenderStartupArgs, | ||
}; | ||
|
||
use crate::utils::property_access; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct ModuleLibraryPlugin {} | ||
|
||
impl ModuleLibraryPlugin {} | ||
|
||
impl Plugin for ModuleLibraryPlugin { | ||
fn name(&self) -> &'static str { | ||
"ModuleLibraryPlugin" | ||
} | ||
|
||
fn render_startup( | ||
&self, | ||
_ctx: PluginContext, | ||
args: &RenderStartupArgs, | ||
) -> PluginRenderStartupHookOutput { | ||
let mut source = ConcatSource::default(); | ||
let mut exports = vec![]; | ||
if let Some(ordered_exports) = args.compilation.exports_info_map.get(&args.module) { | ||
for info in ordered_exports { | ||
let name = to_identifier(info.name.as_ref()); | ||
let var_name = format!("__webpack_exports__{}", name); | ||
source.add(RawSource::from(format!( | ||
"var {var_name} = __webpack_exports__{};\n", | ||
property_access(&vec![info.name.to_string()]) | ||
))); | ||
exports.push(format!("{var_name} as {}", info.name)); | ||
} | ||
} | ||
if !exports.is_empty() { | ||
source.add(RawSource::from(format!( | ||
"export {{ {} }};\n", | ||
exports.join(", ") | ||
))); | ||
} | ||
Ok(Some(source.boxed())) | ||
} | ||
|
||
fn js_chunk_hash( | ||
&self, | ||
_ctx: PluginContext, | ||
args: &mut JsChunkHashArgs, | ||
) -> PluginJsChunkHashHookOutput { | ||
self.name().hash(&mut args.hasher); | ||
args | ||
.compilation | ||
.options | ||
.output | ||
.library | ||
.hash(&mut args.hasher); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.