Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid renaming the export name when outputting a library #8046

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions crates/rspack_plugin_library/src/assign_library_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,20 +401,14 @@ async fn finish_modules(&self, compilation: &mut Compilation) -> Result<()> {
}

for (runtime, export, module_identifier) in runtime_info {
let mut module_graph = compilation.get_module_graph_mut();
if let Some(export) = export {
let exports_info = compilation
.get_module_graph_mut()
.get_export_info(module_identifier, &(export.as_str()).into());
exports_info.set_used(
&mut compilation.get_module_graph_mut(),
UsageState::Used,
Some(&runtime),
);
let export_info = module_graph.get_export_info(module_identifier, &(export.as_str()).into());
export_info.set_used(&mut module_graph, UsageState::Used, Some(&runtime));
export_info.set_can_mangle_use(&mut module_graph, Some(false));
} else {
let exports_info = compilation
.get_module_graph()
.get_exports_info(&module_identifier);
exports_info.set_used_in_unknown_way(&mut compilation.get_module_graph_mut(), Some(&runtime));
let exports_info = module_graph.get_exports_info(&module_identifier);
exports_info.set_used_in_unknown_way(&mut module_graph, Some(&runtime));
}
}
Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default 1;

it('should work', () => {
expect(window.MyLibrary).toEqual(1);
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
output: {
library: {
name: "MyLibrary",
export: "default",
type: "window"
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import("../../../..").TConfigCaseConfig} */
module.exports = {
moduleScope(scope) {
scope.window = {};
}
};
Loading