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!: set default value of concatenateModules to true in production mode #6959

Merged
merged 1 commit into from
Jun 28, 2024
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
2 changes: 1 addition & 1 deletion crates/rspack_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ either = "1"
futures = { workspace = true }
hashlink = { workspace = true }
hex = { workspace = true }
indexmap = { workspace = true }
indexmap = { workspace = true, features = ["rayon"] }
indoc = { workspace = true }
itertools = { workspace = true }
json = { workspace = true }
Expand Down
34 changes: 24 additions & 10 deletions crates/rspack_core/src/concatenated_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use std::{
use dashmap::DashMap;
use indexmap::{IndexMap, IndexSet};
use once_cell::sync::OnceCell;
use rayon::prelude::*;
// use rayon::prelude::*;
use regex::Regex;
use rspack_ast::javascript::Ast;
use rspack_error::{Diagnosable, Diagnostic, DiagnosticKind, Result, TraceableError};
Expand Down Expand Up @@ -598,6 +600,11 @@ impl Module for ConcatenatedModule {
for d in module.get_diagnostics() {
diagnostics_guard.push(d.clone());
}
// populate assets
for asset in &cur_build_info.asset_filenames {
build_info.asset_filenames.insert(asset.clone());
}

// release guard ASAP
drop(diagnostics_guard);

Expand Down Expand Up @@ -644,17 +651,25 @@ impl Module for ConcatenatedModule {
// Generate source code and analyze scopes
// Prepare a ReplaceSource for the final source
//
let mut updated_pairs = vec![];
let arc_map = Arc::new(module_to_info_map);
for (id, info) in arc_map.iter() {
let updated_module_info = self.analyze_module(
compilation,
Arc::clone(&arc_map),
info.clone(),
Some(&merged_runtime),
)?;
updated_pairs.push((*id, updated_module_info));
let tmp: Vec<rspack_error::Result<(rspack_identifier::Identifier, ModuleInfo)>> = arc_map
.par_iter()
.map(|(id, info)| {
let updated_module_info = self.analyze_module(
compilation,
Arc::clone(&arc_map),
info.clone(),
Some(&merged_runtime),
)?;
Ok((*id, updated_module_info))
})
.collect::<Vec<_>>();

let mut updated_pairs = vec![];
for item in tmp.into_iter() {
updated_pairs.push(item?);
}

let mut module_to_info_map = Arc::into_inner(arc_map).expect("reference count should be one");

for (id, module_info) in updated_pairs {
Expand Down Expand Up @@ -1183,7 +1198,6 @@ impl Module for ConcatenatedModule {
)
.as_str(),
));

// https://github.com/webpack/webpack/blob/ac7e531436b0d47cd88451f497cdfd0dad41535d/lib/optimize/ConcatenatedModule.js#L1582
result.add(info.source.clone().expect("should have source"));

Expand Down
17 changes: 7 additions & 10 deletions crates/rspack_core/src/external_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
CodeGenerationResult, Compilation, ConcatenationScope, Context, DependenciesBlock, DependencyId,
ExternalType, FactoryMeta, InitFragmentExt, InitFragmentKey, InitFragmentStage, LibIdentOptions,
Module, ModuleType, NormalInitFragment, RuntimeGlobals, RuntimeSpec, SourceType,
StaticExportsDependency, StaticExportsSpec, NAMESPACE_OBJECT_EXPORT,
StaticExportsDependency, StaticExportsSpec, Template, NAMESPACE_OBJECT_EXPORT,
};
use crate::{ChunkGraph, ModuleGraph};

Expand Down Expand Up @@ -245,21 +245,17 @@ impl ExternalModule {
),
"module" if let Some(request) = request => {
if compilation.options.output.module {
let id = compilation
.get_module_graph()
.module_graph_module_by_identifier(&self.identifier())
.map(|m| m.id(&compilation.chunk_graph))
.unwrap_or_default();
let identifier = to_identifier(id);
let id = Template::to_identifier(&request.primary);
chunk_init_fragments.push(
NormalInitFragment::new(
format!(
"import * as __WEBPACK_EXTERNAL_MODULE_{identifier}__ from {};\n",
"import * as __WEBPACK_EXTERNAL_MODULE_{}__ from {};\n",
id.clone(),
json_stringify(request.primary())
),
InitFragmentStage::StageHarmonyImports,
0,
InitFragmentKey::ExternalModule(identifier.clone()),
InitFragmentKey::ExternalModule(request.primary().into()),
None,
)
.boxed(),
Expand All @@ -269,10 +265,11 @@ impl ExternalModule {
r#"
var x = y => {{ var x = {{}}; {}(x, y); return x; }}
var y = x => () => x
{} = __WEBPACK_EXTERNAL_MODULE_{identifier}__;
{} = __WEBPACK_EXTERNAL_MODULE_{}__;
"#,
RuntimeGlobals::DEFINE_PROPERTY_GETTERS,
get_namespace_object_export(concatenation_scope),
id.clone()
)
} else {
format!(
Expand Down
Loading
Loading