Skip to content
Merged
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
3 changes: 2 additions & 1 deletion crates/rspack_plugin_runtime/src/module_chunk_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async fn render_chunk(
if chunk.has_entry_module(&compilation.chunk_graph) {
let runtime_chunk_output_name = get_runtime_chunk_output_name(compilation, chunk_ukey).await?;
sources.add(RawStringSource::from(format!(
"import __webpack_require__ from '{}';\n",
"import {{ __webpack_require__ }} from '{}';\n",
get_relative_path(
base_chunk_output_name
.trim_start_matches("/")
Expand Down Expand Up @@ -297,6 +297,7 @@ async fn render_startup(
&compilation.chunk_by_ukey,
&compilation.chunk_group_by_ukey,
);

let base_chunk_output_name = get_chunk_output_name(chunk, compilation).await?;

let mut dependent_load = ConcatSource::default();
Expand Down
13 changes: 3 additions & 10 deletions crates/rspack_plugin_runtime/src/module_chunk_loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,9 @@ async fn runtime_requirements_in_tree(
}
RuntimeGlobals::EXTERNAL_INSTALL_CHUNK if is_enabled_for_chunk => {
has_chunk_loading = true;
if compilation
.chunk_graph
.get_number_of_entry_modules(chunk_ukey)
> 0
{
continue;
} else {
compilation
.add_runtime_module(chunk_ukey, ExportWebpackRequireRuntimeModule::new().boxed())?;
}

compilation
.add_runtime_module(chunk_ukey, ExportWebpackRequireRuntimeModule::new().boxed())?;
}

RuntimeGlobals::HMR_DOWNLOAD_UPDATE_HANDLERS if is_enabled_for_chunk => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use rspack_collections::Identifier;
use rspack_core::{Compilation, RuntimeGlobals, RuntimeModule, impl_runtime_module};

const EXPORT_TEMP_NAME: &str = "__webpack_require_temp__";

#[impl_runtime_module]
#[derive(Debug, Default)]
pub struct ExportWebpackRequireRuntimeModule {
Expand All @@ -20,7 +22,11 @@ impl RuntimeModule for ExportWebpackRequireRuntimeModule {
}

async fn generate(&self, _compilation: &Compilation) -> rspack_error::Result<String> {
Ok(format!("export default {};", RuntimeGlobals::REQUIRE))
Ok(format!(
"var {EXPORT_TEMP_NAME} = {};\nexport {{ {EXPORT_TEMP_NAME} as {} }};\n",
RuntimeGlobals::REQUIRE,
RuntimeGlobals::REQUIRE
))
}

fn should_isolate(&self) -> bool {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = () => "FIXME: __webpack_require__.C is not a function"
module.exports = () => true
Loading