diff --git a/crates/rspack_core/Cargo.toml b/crates/rspack_core/Cargo.toml index cb649ef9a28f..27896dd9e823 100644 --- a/crates/rspack_core/Cargo.toml +++ b/crates/rspack_core/Cargo.toml @@ -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 } diff --git a/crates/rspack_core/src/concatenated_module.rs b/crates/rspack_core/src/concatenated_module.rs index 6e45a357da6d..1bdf2e837e18 100644 --- a/crates/rspack_core/src/concatenated_module.rs +++ b/crates/rspack_core/src/concatenated_module.rs @@ -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}; @@ -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); @@ -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> = 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::>(); + + 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 { @@ -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")); diff --git a/crates/rspack_core/src/external_module.rs b/crates/rspack_core/src/external_module.rs index e433bc6cb1bb..976ff5cf4d0b 100644 --- a/crates/rspack_core/src/external_module.rs +++ b/crates/rspack_core/src/external_module.rs @@ -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}; @@ -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(), @@ -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!( diff --git a/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap index 7a3832eeeac7..3cce7db75d3c 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/StatsAPI.test.js.snap @@ -73,6 +73,7 @@ Object { "nameForCondition": "/tests/fixtures/a.js", "optimizationBailout": Array [ "Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2", + "ModuleConcatenation bailout: Module is not an ECMAScript module", ], "optional": false, "orphan": false, @@ -185,6 +186,7 @@ Object { "nameForCondition": "/tests/fixtures/a.js", "optimizationBailout": Array [ "Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2", + "ModuleConcatenation bailout: Module is not an ECMAScript module", ], "optional": false, "orphan": false, @@ -266,7 +268,7 @@ Object { "related": Object {}, }, "name": "main.js", - "size": 761, + "size": 471, "type": "asset", }, ], @@ -285,7 +287,7 @@ Object { "files": Array [ "main.js", ], - "hash": "c123f3f151ec18149845", + "hash": "e1a612615a3947e12730", "id": "909", "idHints": Array [], "initial": true, @@ -293,84 +295,414 @@ Object { Object { "assets": Array [], "buildTimeExecuted": false, - "built": true, + "built": false, "cacheable": true, "cached": false, "chunks": Array [ "909", ], "codeGenerated": true, - "dependent": true, - "depth": 1, + "dependent": false, + "depth": 0, "errors": 0, "failed": false, - "id": "83", - "identifier": "/tests/fixtures/esm/a.js", - "index": 1, - "index2": 0, - "issuer": "/tests/fixtures/esm/abc.js", - "issuerId": "314", - "issuerName": "./fixtures/esm/abc.js", - "issuerPath": Array [ + "filteredModules": undefined, + "id": "533", + "identifier": "/tests/fixtures/esm/abc.js|0e47874493fdefd960142324ecb88ecc", + "index": 0, + "index2": 3, + "issuer": undefined, + "issuerId": undefined, + "issuerName": undefined, + "issuerPath": Array [], + "moduleType": "javascript/esm", + "modules": Array [ Object { - "id": "314", + "assets": Array [], + "buildTimeExecuted": false, + "built": true, + "cacheable": true, + "cached": false, + "chunks": Array [], + "codeGenerated": false, + "dependent": true, + "depth": 0, + "errors": 0, + "failed": false, + "id": undefined, "identifier": "/tests/fixtures/esm/abc.js", + "index": 0, + "index2": 3, + "issuer": undefined, + "issuerId": undefined, + "issuerName": undefined, + "issuerPath": Array [], + "moduleType": "javascript/auto", "name": "./fixtures/esm/abc.js", + "nameForCondition": "/tests/fixtures/esm/abc.js", + "optimizationBailout": Array [ + "ModuleConcatenation bailout: Module is an entry point", + ], + "optional": false, + "orphan": true, + "postOrderIndex": 3, + "preOrderIndex": 0, + "providedExports": Array [], + "reasons": Array [], + "size": 80, + "sizes": Object { + "javascript": 80, + }, + "type": "module", + "usedExports": Array [], + "warnings": 0, + }, + Object { + "assets": Array [], + "buildTimeExecuted": false, + "built": true, + "cacheable": true, + "cached": false, + "chunks": Array [], + "codeGenerated": false, + "dependent": true, + "depth": 1, + "errors": 0, + "failed": false, + "id": undefined, + "identifier": "/tests/fixtures/esm/a.js", + "index": 1, + "index2": 0, + "issuer": "/tests/fixtures/esm/abc.js", + "issuerId": undefined, + "issuerName": "./fixtures/esm/abc.js", + "issuerPath": Array [ + Object { + "id": undefined, + "identifier": "/tests/fixtures/esm/abc.js", + "name": "./fixtures/esm/abc.js", + }, + ], + "moduleType": "javascript/auto", + "name": "./fixtures/esm/a.js", + "nameForCondition": "/tests/fixtures/esm/a.js", + "optimizationBailout": Array [], + "optional": false, + "orphan": true, + "postOrderIndex": 0, + "preOrderIndex": 1, + "providedExports": Array [ + "a", + "default", + ], + "reasons": Array [ + Object { + "moduleId": undefined, + "moduleIdentifier": "/tests/fixtures/esm/abc.js", + "moduleName": "./fixtures/esm/abc.js", + "type": "esm import", + "userRequest": "./a", + }, + Object { + "moduleId": undefined, + "moduleIdentifier": "/tests/fixtures/esm/abc.js", + "moduleName": "./fixtures/esm/abc.js", + "type": "esm import specifier", + "userRequest": "./a", + }, + ], + "size": 37, + "sizes": Object { + "javascript": 37, + }, + "type": "module", + "usedExports": Array [ + "a", + ], + "warnings": 0, + }, + Object { + "assets": Array [], + "buildTimeExecuted": false, + "built": true, + "cacheable": true, + "cached": false, + "chunks": Array [], + "codeGenerated": false, + "dependent": true, + "depth": 1, + "errors": 0, + "failed": false, + "id": undefined, + "identifier": "/tests/fixtures/esm/b.js", + "index": 2, + "index2": 1, + "issuer": "/tests/fixtures/esm/abc.js", + "issuerId": undefined, + "issuerName": "./fixtures/esm/abc.js", + "issuerPath": Array [ + Object { + "id": undefined, + "identifier": "/tests/fixtures/esm/abc.js", + "name": "./fixtures/esm/abc.js", + }, + ], + "moduleType": "javascript/auto", + "name": "./fixtures/esm/b.js", + "nameForCondition": "/tests/fixtures/esm/b.js", + "optimizationBailout": Array [], + "optional": false, + "orphan": true, + "postOrderIndex": 1, + "preOrderIndex": 2, + "providedExports": Array [ + "b", + "default", + ], + "reasons": Array [ + Object { + "moduleId": undefined, + "moduleIdentifier": "/tests/fixtures/esm/abc.js", + "moduleName": "./fixtures/esm/abc.js", + "type": "esm import", + "userRequest": "./b", + }, + Object { + "moduleId": undefined, + "moduleIdentifier": "/tests/fixtures/esm/abc.js", + "moduleName": "./fixtures/esm/abc.js", + "type": "esm import specifier", + "userRequest": "./b", + }, + ], + "size": 38, + "sizes": Object { + "javascript": 38, + }, + "type": "module", + "usedExports": Array [ + "default", + ], + "warnings": 0, + }, + Object { + "assets": Array [], + "buildTimeExecuted": false, + "built": true, + "cacheable": true, + "cached": false, + "chunks": Array [], + "codeGenerated": false, + "dependent": true, + "depth": 1, + "errors": 0, + "failed": false, + "id": undefined, + "identifier": "/tests/fixtures/esm/c.js", + "index": 3, + "index2": 2, + "issuer": "/tests/fixtures/esm/abc.js", + "issuerId": undefined, + "issuerName": "./fixtures/esm/abc.js", + "issuerPath": Array [ + Object { + "id": undefined, + "identifier": "/tests/fixtures/esm/abc.js", + "name": "./fixtures/esm/abc.js", + }, + ], + "moduleType": "javascript/auto", + "name": "./fixtures/esm/c.js", + "nameForCondition": "/tests/fixtures/esm/c.js", + "optimizationBailout": Array [], + "optional": false, + "orphan": true, + "postOrderIndex": 2, + "preOrderIndex": 3, + "providedExports": Array [ + "c", + "default", + ], + "reasons": Array [ + Object { + "moduleId": undefined, + "moduleIdentifier": "/tests/fixtures/esm/abc.js", + "moduleName": "./fixtures/esm/abc.js", + "type": "esm import", + "userRequest": "./c", + }, + Object { + "moduleId": undefined, + "moduleIdentifier": "/tests/fixtures/esm/abc.js", + "moduleName": "./fixtures/esm/abc.js", + "type": "esm import specifier", + "userRequest": "./c", + }, + ], + "size": 37, + "sizes": Object { + "javascript": 37, + }, + "type": "module", + "usedExports": true, + "warnings": 0, }, ], - "moduleType": "javascript/auto", - "name": "./fixtures/esm/a.js", - "nameForCondition": "/tests/fixtures/esm/a.js", + "name": "./fixtures/esm/abc.js + 3 modules", + "nameForCondition": "/tests/fixtures/esm/abc.js", "optimizationBailout": Array [], "optional": false, "orphan": false, - "postOrderIndex": 0, - "preOrderIndex": 1, - "providedExports": Array [ - "a", - "default", - ], + "postOrderIndex": 3, + "preOrderIndex": 0, + "providedExports": Array [], "reasons": Array [ Object { - "moduleId": "314", - "moduleIdentifier": "/tests/fixtures/esm/abc.js", - "moduleName": "./fixtures/esm/abc.js", - "type": "esm import", - "userRequest": "./a", - }, - Object { - "moduleId": "314", - "moduleIdentifier": "/tests/fixtures/esm/abc.js", - "moduleName": "./fixtures/esm/abc.js", - "type": "esm import specifier", - "userRequest": "./a", + "moduleId": undefined, + "moduleIdentifier": undefined, + "moduleName": undefined, + "type": "entry", + "userRequest": "./fixtures/esm/abc", }, ], - "size": 37, + "size": 192, "sizes": Object { - "javascript": 37, + "javascript": 192, }, "type": "module", - "usedExports": Array [ - "a", - ], + "usedExports": Array [], "warnings": 0, }, + ], + "names": Array [ + "main", + ], + "origins": Array [ + Object { + "loc": "main", + "module": "", + "moduleId": "", + "moduleIdentifier": "", + "moduleName": "", + "request": "./fixtures/esm/abc", + }, + ], + "parents": Array [], + "reason": undefined, + "rendered": true, + "runtime": Array [ + "main", + ], + "siblings": Array [], + "size": 192, + "sizes": Object { + "javascript": 192, + "runtime": 677, + }, + "type": "chunk", + }, + ], + "entrypoints": Object { + "main": Object { + "assets": Array [ + Object { + "name": "main.js", + "size": 471, + }, + ], + "assetsSize": 471, + "auxiliaryAssets": Array [], + "auxiliaryAssetsSize": 0, + "children": Object {}, + "chunks": Array [ + "909", + ], + "name": "main", + }, + }, + "errors": Array [], + "errorsCount": 0, + "filteredModules": undefined, + "hash": "9ec361d93943966f85ad", + "modules": Array [ + Object { + "assets": Array [], + "buildTimeExecuted": false, + "built": true, + "cacheable": true, + "cached": false, + "chunks": Array [], + "codeGenerated": false, + "dependent": undefined, + "depth": 0, + "errors": 0, + "failed": false, + "id": undefined, + "identifier": "/tests/fixtures/esm/abc.js", + "index": 0, + "index2": 3, + "issuer": undefined, + "issuerId": undefined, + "issuerName": undefined, + "issuerPath": Array [], + "moduleType": "javascript/auto", + "name": "./fixtures/esm/abc.js", + "nameForCondition": "/tests/fixtures/esm/abc.js", + "optimizationBailout": Array [ + "ModuleConcatenation bailout: Module is an entry point", + ], + "optional": false, + "orphan": true, + "postOrderIndex": 3, + "preOrderIndex": 0, + "providedExports": Array [], + "reasons": Array [], + "size": 80, + "sizes": Object { + "javascript": 80, + }, + "type": "module", + "usedExports": Array [], + "warnings": 0, + }, + Object { + "assets": Array [], + "buildTimeExecuted": false, + "built": false, + "cacheable": true, + "cached": false, + "chunks": Array [ + "909", + ], + "codeGenerated": true, + "dependent": undefined, + "depth": 0, + "errors": 0, + "failed": false, + "filteredModules": undefined, + "id": "533", + "identifier": "/tests/fixtures/esm/abc.js|0e47874493fdefd960142324ecb88ecc", + "index": 0, + "index2": 3, + "issuer": undefined, + "issuerId": undefined, + "issuerName": undefined, + "issuerPath": Array [], + "moduleType": "javascript/esm", + "modules": Array [ Object { "assets": Array [], "buildTimeExecuted": false, "built": true, "cacheable": true, "cached": false, - "chunks": Array [ - "909", - ], - "codeGenerated": true, - "dependent": false, + "chunks": Array [], + "codeGenerated": false, + "dependent": undefined, "depth": 0, "errors": 0, "failed": false, - "id": "314", + "id": undefined, "identifier": "/tests/fixtures/esm/abc.js", "index": 0, "index2": 3, @@ -381,27 +713,85 @@ Object { "moduleType": "javascript/auto", "name": "./fixtures/esm/abc.js", "nameForCondition": "/tests/fixtures/esm/abc.js", - "optimizationBailout": Array [], + "optimizationBailout": Array [ + "ModuleConcatenation bailout: Module is an entry point", + ], "optional": false, - "orphan": false, + "orphan": true, "postOrderIndex": 3, "preOrderIndex": 0, "providedExports": Array [], + "reasons": Array [], + "size": 80, + "sizes": Object { + "javascript": 80, + }, + "type": "module", + "usedExports": Array [], + "warnings": 0, + }, + Object { + "assets": Array [], + "buildTimeExecuted": false, + "built": true, + "cacheable": true, + "cached": false, + "chunks": Array [], + "codeGenerated": false, + "dependent": undefined, + "depth": 1, + "errors": 0, + "failed": false, + "id": undefined, + "identifier": "/tests/fixtures/esm/a.js", + "index": 1, + "index2": 0, + "issuer": "/tests/fixtures/esm/abc.js", + "issuerId": undefined, + "issuerName": "./fixtures/esm/abc.js", + "issuerPath": Array [ + Object { + "id": undefined, + "identifier": "/tests/fixtures/esm/abc.js", + "name": "./fixtures/esm/abc.js", + }, + ], + "moduleType": "javascript/auto", + "name": "./fixtures/esm/a.js", + "nameForCondition": "/tests/fixtures/esm/a.js", + "optimizationBailout": Array [], + "optional": false, + "orphan": true, + "postOrderIndex": 0, + "preOrderIndex": 1, + "providedExports": Array [ + "a", + "default", + ], "reasons": Array [ Object { "moduleId": undefined, - "moduleIdentifier": undefined, - "moduleName": undefined, - "type": "entry", - "userRequest": "./fixtures/esm/abc", + "moduleIdentifier": "/tests/fixtures/esm/abc.js", + "moduleName": "./fixtures/esm/abc.js", + "type": "esm import", + "userRequest": "./a", + }, + Object { + "moduleId": undefined, + "moduleIdentifier": "/tests/fixtures/esm/abc.js", + "moduleName": "./fixtures/esm/abc.js", + "type": "esm import specifier", + "userRequest": "./a", }, ], - "size": 80, + "size": 37, "sizes": Object { - "javascript": 80, + "javascript": 37, }, "type": "module", - "usedExports": Array [], + "usedExports": Array [ + "a", + ], "warnings": 0, }, Object { @@ -410,24 +800,22 @@ Object { "built": true, "cacheable": true, "cached": false, - "chunks": Array [ - "909", - ], - "codeGenerated": true, - "dependent": true, + "chunks": Array [], + "codeGenerated": false, + "dependent": undefined, "depth": 1, "errors": 0, "failed": false, - "id": "178", + "id": undefined, "identifier": "/tests/fixtures/esm/b.js", "index": 2, "index2": 1, "issuer": "/tests/fixtures/esm/abc.js", - "issuerId": "314", + "issuerId": undefined, "issuerName": "./fixtures/esm/abc.js", "issuerPath": Array [ Object { - "id": "314", + "id": undefined, "identifier": "/tests/fixtures/esm/abc.js", "name": "./fixtures/esm/abc.js", }, @@ -437,7 +825,7 @@ Object { "nameForCondition": "/tests/fixtures/esm/b.js", "optimizationBailout": Array [], "optional": false, - "orphan": false, + "orphan": true, "postOrderIndex": 1, "preOrderIndex": 2, "providedExports": Array [ @@ -446,14 +834,14 @@ Object { ], "reasons": Array [ Object { - "moduleId": "314", + "moduleId": undefined, "moduleIdentifier": "/tests/fixtures/esm/abc.js", "moduleName": "./fixtures/esm/abc.js", "type": "esm import", "userRequest": "./b", }, Object { - "moduleId": "314", + "moduleId": undefined, "moduleIdentifier": "/tests/fixtures/esm/abc.js", "moduleName": "./fixtures/esm/abc.js", "type": "esm import specifier", @@ -476,24 +864,22 @@ Object { "built": true, "cacheable": true, "cached": false, - "chunks": Array [ - "909", - ], - "codeGenerated": true, - "dependent": true, + "chunks": Array [], + "codeGenerated": false, + "dependent": undefined, "depth": 1, "errors": 0, "failed": false, - "id": "609", + "id": undefined, "identifier": "/tests/fixtures/esm/c.js", "index": 3, "index2": 2, "issuer": "/tests/fixtures/esm/abc.js", - "issuerId": "314", + "issuerId": undefined, "issuerName": "./fixtures/esm/abc.js", "issuerPath": Array [ Object { - "id": "314", + "id": undefined, "identifier": "/tests/fixtures/esm/abc.js", "name": "./fixtures/esm/abc.js", }, @@ -503,7 +889,7 @@ Object { "nameForCondition": "/tests/fixtures/esm/c.js", "optimizationBailout": Array [], "optional": false, - "orphan": false, + "orphan": true, "postOrderIndex": 2, "preOrderIndex": 3, "providedExports": Array [ @@ -512,14 +898,14 @@ Object { ], "reasons": Array [ Object { - "moduleId": "314", + "moduleId": undefined, "moduleIdentifier": "/tests/fixtures/esm/abc.js", "moduleName": "./fixtures/esm/abc.js", "type": "esm import", "userRequest": "./c", }, Object { - "moduleId": "314", + "moduleId": undefined, "moduleIdentifier": "/tests/fixtures/esm/abc.js", "moduleName": "./fixtures/esm/abc.js", "type": "esm import specifier", @@ -535,81 +921,7 @@ Object { "warnings": 0, }, ], - "names": Array [ - "main", - ], - "origins": Array [ - Object { - "loc": "main", - "module": "", - "moduleId": "", - "moduleIdentifier": "", - "moduleName": "", - "request": "./fixtures/esm/abc", - }, - ], - "parents": Array [], - "reason": undefined, - "rendered": true, - "runtime": Array [ - "main", - ], - "siblings": Array [], - "size": 192, - "sizes": Object { - "javascript": 192, - "runtime": 677, - }, - "type": "chunk", - }, - ], - "entrypoints": Object { - "main": Object { - "assets": Array [ - Object { - "name": "main.js", - "size": 761, - }, - ], - "assetsSize": 761, - "auxiliaryAssets": Array [], - "auxiliaryAssetsSize": 0, - "children": Object {}, - "chunks": Array [ - "909", - ], - "name": "main", - }, - }, - "errors": Array [], - "errorsCount": 0, - "filteredModules": undefined, - "hash": "425b09c676aa5e20e258", - "modules": Array [ - Object { - "assets": Array [], - "buildTimeExecuted": false, - "built": true, - "cacheable": true, - "cached": false, - "chunks": Array [ - "909", - ], - "codeGenerated": true, - "dependent": undefined, - "depth": 0, - "errors": 0, - "failed": false, - "id": "314", - "identifier": "/tests/fixtures/esm/abc.js", - "index": 0, - "index2": 3, - "issuer": undefined, - "issuerId": undefined, - "issuerName": undefined, - "issuerPath": Array [], - "moduleType": "javascript/auto", - "name": "./fixtures/esm/abc.js", + "name": "./fixtures/esm/abc.js + 3 modules", "nameForCondition": "/tests/fixtures/esm/abc.js", "optimizationBailout": Array [], "optional": false, @@ -626,9 +938,9 @@ Object { "userRequest": "./fixtures/esm/abc", }, ], - "size": 80, + "size": 192, "sizes": Object { - "javascript": 80, + "javascript": 192, }, "type": "module", "usedExports": Array [], @@ -640,24 +952,22 @@ Object { "built": true, "cacheable": true, "cached": false, - "chunks": Array [ - "909", - ], - "codeGenerated": true, + "chunks": Array [], + "codeGenerated": false, "dependent": undefined, "depth": 1, "errors": 0, "failed": false, - "id": "83", + "id": undefined, "identifier": "/tests/fixtures/esm/a.js", "index": 1, "index2": 0, "issuer": "/tests/fixtures/esm/abc.js", - "issuerId": "314", + "issuerId": undefined, "issuerName": "./fixtures/esm/abc.js", "issuerPath": Array [ Object { - "id": "314", + "id": undefined, "identifier": "/tests/fixtures/esm/abc.js", "name": "./fixtures/esm/abc.js", }, @@ -667,7 +977,7 @@ Object { "nameForCondition": "/tests/fixtures/esm/a.js", "optimizationBailout": Array [], "optional": false, - "orphan": false, + "orphan": true, "postOrderIndex": 0, "preOrderIndex": 1, "providedExports": Array [ @@ -676,14 +986,14 @@ Object { ], "reasons": Array [ Object { - "moduleId": "314", + "moduleId": undefined, "moduleIdentifier": "/tests/fixtures/esm/abc.js", "moduleName": "./fixtures/esm/abc.js", "type": "esm import", "userRequest": "./a", }, Object { - "moduleId": "314", + "moduleId": undefined, "moduleIdentifier": "/tests/fixtures/esm/abc.js", "moduleName": "./fixtures/esm/abc.js", "type": "esm import specifier", @@ -706,24 +1016,22 @@ Object { "built": true, "cacheable": true, "cached": false, - "chunks": Array [ - "909", - ], - "codeGenerated": true, + "chunks": Array [], + "codeGenerated": false, "dependent": undefined, "depth": 1, "errors": 0, "failed": false, - "id": "178", + "id": undefined, "identifier": "/tests/fixtures/esm/b.js", "index": 2, "index2": 1, "issuer": "/tests/fixtures/esm/abc.js", - "issuerId": "314", + "issuerId": undefined, "issuerName": "./fixtures/esm/abc.js", "issuerPath": Array [ Object { - "id": "314", + "id": undefined, "identifier": "/tests/fixtures/esm/abc.js", "name": "./fixtures/esm/abc.js", }, @@ -733,7 +1041,7 @@ Object { "nameForCondition": "/tests/fixtures/esm/b.js", "optimizationBailout": Array [], "optional": false, - "orphan": false, + "orphan": true, "postOrderIndex": 1, "preOrderIndex": 2, "providedExports": Array [ @@ -742,14 +1050,14 @@ Object { ], "reasons": Array [ Object { - "moduleId": "314", + "moduleId": undefined, "moduleIdentifier": "/tests/fixtures/esm/abc.js", "moduleName": "./fixtures/esm/abc.js", "type": "esm import", "userRequest": "./b", }, Object { - "moduleId": "314", + "moduleId": undefined, "moduleIdentifier": "/tests/fixtures/esm/abc.js", "moduleName": "./fixtures/esm/abc.js", "type": "esm import specifier", @@ -772,24 +1080,22 @@ Object { "built": true, "cacheable": true, "cached": false, - "chunks": Array [ - "909", - ], - "codeGenerated": true, + "chunks": Array [], + "codeGenerated": false, "dependent": undefined, "depth": 1, "errors": 0, "failed": false, - "id": "609", + "id": undefined, "identifier": "/tests/fixtures/esm/c.js", "index": 3, "index2": 2, "issuer": "/tests/fixtures/esm/abc.js", - "issuerId": "314", + "issuerId": undefined, "issuerName": "./fixtures/esm/abc.js", "issuerPath": Array [ Object { - "id": "314", + "id": undefined, "identifier": "/tests/fixtures/esm/abc.js", "name": "./fixtures/esm/abc.js", }, @@ -799,7 +1105,7 @@ Object { "nameForCondition": "/tests/fixtures/esm/c.js", "optimizationBailout": Array [], "optional": false, - "orphan": false, + "orphan": true, "postOrderIndex": 2, "preOrderIndex": 3, "providedExports": Array [ @@ -808,14 +1114,14 @@ Object { ], "reasons": Array [ Object { - "moduleId": "314", + "moduleId": undefined, "moduleIdentifier": "/tests/fixtures/esm/abc.js", "moduleName": "./fixtures/esm/abc.js", "type": "esm import", "userRequest": "./c", }, Object { - "moduleId": "314", + "moduleId": undefined, "moduleIdentifier": "/tests/fixtures/esm/abc.js", "moduleName": "./fixtures/esm/abc.js", "type": "esm import specifier", @@ -956,10 +1262,10 @@ Object { "assets": Array [ Object { "name": "main.js", - "size": 761, + "size": 471, }, ], - "assetsSize": 761, + "assetsSize": 471, "auxiliaryAssets": Array [], "auxiliaryAssetsSize": 0, "children": Object {}, @@ -1158,6 +1464,7 @@ Object { "nameForCondition": "/tests/fixtures/a.js", "optimizationBailout": Array [ "Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2", + "ModuleConcatenation bailout: Module is not an ECMAScript module", ], "optional": false, "orphan": false, @@ -1224,6 +1531,7 @@ Object { "nameForCondition": "/tests/fixtures/a.js", "optimizationBailout": Array [ "Statement with side_effects in source code at ./fixtures/a.js?a=1:1:0-3:2", + "ModuleConcatenation bailout: Module is not an ECMAScript module", ], "optional": false, "orphan": false, @@ -1284,6 +1592,7 @@ Object { "nameForCondition": "/tests/fixtures/abc-query.js", "optimizationBailout": Array [ "Statement with side_effects in source code at ./fixtures/abc-query.js:1:0-31", + "ModuleConcatenation bailout: Module is not an ECMAScript module", ], "optional": false, "orphan": false, @@ -1347,6 +1656,7 @@ exports.c = require(\\"./c?c=3\\"); "nameForCondition": "/tests/fixtures/c.js", "optimizationBailout": Array [ "Statement with side_effects in source code at ./fixtures/c.js?c=3:1:0-4:2", + "ModuleConcatenation bailout: Module is not an ECMAScript module", ], "optional": false, "orphan": false, @@ -1460,6 +1770,7 @@ exports.c = require(\\"./c?c=3\\"); "nameForCondition": "/tests/fixtures/abc-query.js", "optimizationBailout": Array [ "Statement with side_effects in source code at ./fixtures/abc-query.js:1:0-31", + "ModuleConcatenation bailout: Module is not an ECMAScript module", ], "optional": false, "orphan": false, @@ -1523,6 +1834,7 @@ exports.c = require(\\"./c?c=3\\"); "nameForCondition": "/tests/fixtures/a.js", "optimizationBailout": Array [ "Statement with side_effects in source code at ./fixtures/a.js?a=1:1:0-3:2", + "ModuleConcatenation bailout: Module is not an ECMAScript module", ], "optional": false, "orphan": false, @@ -1589,6 +1901,7 @@ exports.c = require(\\"./c?c=3\\"); "nameForCondition": "/tests/fixtures/c.js", "optimizationBailout": Array [ "Statement with side_effects in source code at ./fixtures/c.js?c=3:1:0-4:2", + "ModuleConcatenation bailout: Module is not an ECMAScript module", ], "optional": false, "orphan": false, @@ -1661,6 +1974,7 @@ exports.c = require(\\"./c?c=3\\"); "nameForCondition": "/tests/fixtures/a.js", "optimizationBailout": Array [ "Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2", + "ModuleConcatenation bailout: Module is not an ECMAScript module", ], "optional": false, "orphan": false, diff --git a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap index e52445dd13c0..c1ffea581053 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap @@ -2,41 +2,63 @@ exports[`statsOutput statsOutput/auxiliary-files-test should print correct stats for 1`] = ` "PublicPath: auto -asset bundle.js 2.49 KiB {909} [emitted] (name: main) +asset bundle.js 2.3 KiB {909} [emitted] (name: main) asset 2710c5e36f8babb0a3a4.png 7 bytes {909} [emitted] [immutable] [from: raw.png] (name: main) -Entrypoint main 2.49 KiB (7 bytes) = bundle.js 2.49 KiB (2710c5e36f8babb0a3a4.png 7 bytes) -chunk {909} (runtime: main) bundle.js (main) 7 bytes (asset) 117 bytes (javascript) 1.28 KiB (runtime) [entry] [rendered] +Entrypoint main 2.3 KiB (7 bytes) = bundle.js 2.3 KiB (2710c5e36f8babb0a3a4.png 7 bytes) +chunk {909} (runtime: main) bundle.js (main) 7 bytes (asset) 159 bytes (javascript) 1.28 KiB (runtime) [entry] [rendered] > ./index main - ./index.js [10] 75 bytes {909} [depth 0] [built] [code generated] + ./index.js + 1 modules [686] 117 bytes {909} [depth 0] [code generated] [no exports] [no exports used] entry ./index - ./raw.png [193] 7 bytes (asset) 42 bytes (javascript) {909} [depth 1] [dependent] [built] [code generated] + | ./index.js 75 bytes [depth 0] [orphan] [dependent] [built] + | [no exports] + | [no exports used] + | ModuleConcatenation bailout: Module is an entry point + | ./raw.png [193] 7 bytes (asset) 42 bytes (javascript) {909} [depth 1] [built] [code generated] + | [no exports] + | [no exports used] + | esm import ./raw.png + ./raw.png [193] 7 bytes (asset) 42 bytes (javascript) {909} [depth 1] [built] [code generated] [no exports] [no exports used] - esm import ./raw.png [10] -built modules 118 bytes (javascript) 7 bytes (asset) [built] - ./index.js [10] 75 bytes {909} [depth 0] [built] [code generated] + esm import ./raw.png +code generated modules 1.28 KiB (runtime) 159 bytes (javascript) 7 bytes (asset) [code generated] + runtime modules 1.28 KiB + webpack/runtime/global 223 bytes {909} [code generated] + [no exports] + [used exports unknown] + webpack/runtime/auto_public_path 1.06 KiB {909} [code generated] + [no exports] + [used exports unknown] + ./index.js + 1 modules [686] 117 bytes {909} [depth 0] [code generated] [no exports] [no exports used] entry ./index - ./stringModule.js 1 bytes [depth 1] [orphan] [built] - [no exports] - [module unused] - esm import ./stringModule [10] + | ./index.js 75 bytes [depth 0] [orphan] [built] + | [no exports] + | [no exports used] + | ModuleConcatenation bailout: Module is an entry point + | ./raw.png [193] 7 bytes (asset) 42 bytes (javascript) {909} [depth 1] [built] [code generated] + | [no exports] + | [no exports used] + | esm import ./raw.png ./raw.png [193] 7 bytes (asset) 42 bytes (javascript) {909} [depth 1] [built] [code generated] [no exports] [no exports used] - esm import ./raw.png [10] -runtime modules 1.28 KiB - webpack/runtime/global 223 bytes {909} [code generated] + esm import ./raw.png +orphan modules 76 bytes [orphan] + ./index.js 75 bytes [depth 0] [orphan] [built] [no exports] - [used exports unknown] - webpack/runtime/auto_public_path 1.06 KiB {909} [code generated] + [no exports used] + ModuleConcatenation bailout: Module is an entry point + ./stringModule.js 1 bytes [depth 1] [orphan] [built] [no exports] - [used exports unknown] + [module unused] + ModuleConcatenation bailout: Module is not an ECMAScript module + esm import ./stringModule [686] -Rspack compiled successfully (be13a1b38364d3c54ae0)" +Rspack compiled successfully (c12084bf03e12a353092)" `; exports[`statsOutput statsOutput/builtin-swc-loader-parse-error should print correct stats for 1`] = ` @@ -417,21 +439,14 @@ Rspack x.x.x compiled successfully in X s" `; exports[`statsOutput statsOutput/side-effects-bailouts should print correct stats for 1`] = ` -"asset main.js 1.73 KiB {909} [emitted] (name: main) -Entrypoint main 1.73 KiB = main.js -chunk {909} (runtime: main) main.js (main) 91 bytes (javascript) 397 bytes (runtime) [entry] [rendered] -runtime modules 397 bytes 2 modules -cacheable modules 91 bytes - ./index.js [10] 35 bytes {909} [built] [code generated] - [no exports] - [no exports used] - entry ./index.js - ./lib.js [467] 56 bytes {909} [built] [code generated] - [exports: test] - [all exports used] - Statement with side_effects in source code at ./lib.js:5:0-9 - esm import ./lib.js [10] - esm import specifier ./lib.js [10] +"asset main.js 207 bytes {909} [emitted] (name: main) +Entrypoint main 207 bytes = main.js +chunk {909} (runtime: main) main.js (main) 91 bytes [entry] [rendered] +orphan modules 91 bytes [orphan] 2 modules +./index.js + 1 modules [911] 91 bytes {909} [code generated] + [no exports] + [no exports used] + entry ./index.js Rspack x.x.x compiled successfully in X s" `; diff --git a/packages/rspack-test-tools/tests/configCases/container-1-5/1-transitive-overriding/rspack.config.js b/packages/rspack-test-tools/tests/configCases/container-1-5/1-transitive-overriding/rspack.config.js index bebd1a3a5ce4..89ef36af5b4b 100644 --- a/packages/rspack-test-tools/tests/configCases/container-1-5/1-transitive-overriding/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/container-1-5/1-transitive-overriding/rspack.config.js @@ -4,7 +4,8 @@ const { ModuleFederationPlugin } = require("@rspack/core").container; module.exports = { optimization: { chunkIds: "named", - moduleIds: "named" + moduleIds: "named", + concatenateModules: false }, output: { uniqueName: "1-transitive-overriding" diff --git a/packages/rspack-test-tools/tests/configCases/container-1-5/2-transitive-overriding/rspack.config.js b/packages/rspack-test-tools/tests/configCases/container-1-5/2-transitive-overriding/rspack.config.js index 797457edab96..a70fad7e5910 100644 --- a/packages/rspack-test-tools/tests/configCases/container-1-5/2-transitive-overriding/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/container-1-5/2-transitive-overriding/rspack.config.js @@ -4,7 +4,8 @@ const { ModuleFederationPlugin } = require("@rspack/core").container; module.exports = { optimization: { chunkIds: "named", - moduleIds: "named" + moduleIds: "named", + concatenateModules: false, }, output: { uniqueName: "2-transitive-overriding" diff --git a/packages/rspack-test-tools/tests/configCases/container-1-5/federation-instance-in-runtime-plugin/rspack.config.js b/packages/rspack-test-tools/tests/configCases/container-1-5/federation-instance-in-runtime-plugin/rspack.config.js index b715d04b144f..43563aeead01 100644 --- a/packages/rspack-test-tools/tests/configCases/container-1-5/federation-instance-in-runtime-plugin/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/container-1-5/federation-instance-in-runtime-plugin/rspack.config.js @@ -2,6 +2,10 @@ const { ModuleFederationPlugin } = require("@rspack/core").container; /** @type {import("@rspack/core").Configuration} */ module.exports = { + optimization: { + // concatenateModules: false, + moduleIds: 'named' + }, plugins: [ new ModuleFederationPlugin({ runtimePlugins: ["./plugin.js"] diff --git a/packages/rspack-test-tools/tests/configCases/hooks/after-resolve-resource/rspack.config.js b/packages/rspack-test-tools/tests/configCases/hooks/after-resolve-resource/rspack.config.js index 6b335c4b3afa..bc09a3311591 100644 --- a/packages/rspack-test-tools/tests/configCases/hooks/after-resolve-resource/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/hooks/after-resolve-resource/rspack.config.js @@ -9,7 +9,8 @@ module.exports = [ filename: "resource.js" }, optimization: { - moduleIds: "named" + moduleIds: "named", + concatenateModules: false }, plugins: [{ apply(compiler) { @@ -31,7 +32,8 @@ module.exports = [ filename: "request.js" }, optimization: { - moduleIds: "named" + moduleIds: "named", + concatenateModules: false, }, plugins: [{ apply(compiler) { @@ -54,7 +56,8 @@ module.exports = [ filename: "duplicate.js" }, optimization: { - moduleIds: "named" + moduleIds: "named", + concatenateModules: false, }, plugins: [{ apply(compiler) { diff --git a/packages/rspack-test-tools/tests/configCases/runtime/namespace-cache/rspack.config.js b/packages/rspack-test-tools/tests/configCases/runtime/namespace-cache/rspack.config.js index 06270f03b5d5..a2784a463a6c 100644 --- a/packages/rspack-test-tools/tests/configCases/runtime/namespace-cache/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/runtime/namespace-cache/rspack.config.js @@ -20,5 +20,8 @@ module.exports = { } } ] + }, + optimization: { + concatenateModules: false } }; diff --git a/packages/rspack-test-tools/tests/configCases/source-map/verify-es6-minify/rspack.config.js b/packages/rspack-test-tools/tests/configCases/source-map/verify-es6-minify/rspack.config.js index afb71214a9b6..9407d63d685d 100644 --- a/packages/rspack-test-tools/tests/configCases/source-map/verify-es6-minify/rspack.config.js +++ b/packages/rspack-test-tools/tests/configCases/source-map/verify-es6-minify/rspack.config.js @@ -2,7 +2,8 @@ module.exports = { devtool: "source-map", optimization: { - minimize: true + minimize: true, + concatenateModules: false, }, externals: ["source-map"], externalsType: "commonjs" diff --git a/packages/rspack-test-tools/tests/configCases/source-map/verify-es6/index.js b/packages/rspack-test-tools/tests/configCases/source-map/verify-es6/index.js index a2ddb1e62372..6f7d2410bb08 100644 --- a/packages/rspack-test-tools/tests/configCases/source-map/verify-es6/index.js +++ b/packages/rspack-test-tools/tests/configCases/source-map/verify-es6/index.js @@ -12,9 +12,9 @@ it("verify es6 (esmodule) bundle source map", async () => { const map = JSON.parse(source); expect(map.sources).toEqual([ "webpack:///../../../../dist/helper/util/checkSourceMap.js", - "webpack:///./a.js", - "webpack:///./b-dir/b.js", "webpack:///./b-dir/c-dir/c.js", + "webpack:///./b-dir/b.js", + "webpack:///./a.js", "webpack:///./index.js", ]); expect(map.file).toEqual("bundle0.js"); diff --git a/packages/rspack-test-tools/tests/defaultsCases/mode/production.js b/packages/rspack-test-tools/tests/defaultsCases/mode/production.js index 7e1621489f82..0f917c52ebd7 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/mode/production.js +++ b/packages/rspack-test-tools/tests/defaultsCases/mode/production.js @@ -12,10 +12,11 @@ module.exports = { + "mode": "production", @@ ... @@ - "chunkIds": "natural", - + "chunkIds": "deterministic", - @@ ... @@ + - "concatenateModules": false, - "innerGraph": false, - "mangleExports": false, + + "chunkIds": "deterministic", + + "concatenateModules": true, + "innerGraph": true, + "mangleExports": true, @@ ... @@ diff --git a/packages/rspack-test-tools/tests/defaultsCases/mode/undefined.js b/packages/rspack-test-tools/tests/defaultsCases/mode/undefined.js index 71933323275b..9b252e24eaea 100644 --- a/packages/rspack-test-tools/tests/defaultsCases/mode/undefined.js +++ b/packages/rspack-test-tools/tests/defaultsCases/mode/undefined.js @@ -12,10 +12,11 @@ module.exports = { + "mode": undefined, @@ ... @@ - "chunkIds": "natural", - + "chunkIds": "deterministic", - @@ ... @@ + - "concatenateModules": false, - "innerGraph": false, - "mangleExports": false, + + "chunkIds": "deterministic", + + "concatenateModules": true, + "innerGraph": true, + "mangleExports": true, @@ ... @@ diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/test.js b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/test.js index 5009bad4ed10..2cb60889e6db 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/test.js +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/duplicate/test.js @@ -6,7 +6,8 @@ module.exports = { context: __dirname, entry: "./duplicate.js", optimization: { - moduleIds: "named" + moduleIds: "named", + concatenateModules: false }, plugins: [ { diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt index 125046707d92..0669de8e0a7b 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/request/output.snap.txt @@ -10,11 +10,6 @@ module.exports = "a"; module.exports = "b"; -}), -"fs": (function (module) { -"use strict"; -module.exports = require("fs"); - }), }); @@ -80,21 +75,26 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { "use strict"; -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_a__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./c.js"); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_b__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("fs"); -/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_2__); + +// EXTERNAL MODULE: ./a.js +let a_ = __webpack_require__("./a.js"); +let a_default = /*#__PURE__*/__webpack_require__.n(a_); +// EXTERNAL MODULE: ./c.js +let c_ = __webpack_require__("./c.js"); +let c_default = /*#__PURE__*/__webpack_require__.n(c_); +;// CONCATENATED MODULE: external "fs" +var external_fs_namespaceObject = require("fs"); +let external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_namespaceObject); +;// CONCATENATED MODULE: ./request.js it("should modify request by after resolve hook", () => { - expect((_a__WEBPACK_IMPORTED_MODULE_0___default())).toBe("a"); - expect((_b__WEBPACK_IMPORTED_MODULE_1___default())).toBe("b"); + expect((a_default())).toBe("a"); + expect((c_default())).toBe("b"); const ext = ".js"; - expect(fs__WEBPACK_IMPORTED_MODULE_2___default().readFileSync(__filename, "utf-8")).toContain("./c" + ext); + expect(external_fs_default().readFileSync(__filename, "utf-8")).toContain("./c" + ext); }); })(); diff --git a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt index af3ec4fe6c95..bb3d9ca31881 100644 --- a/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt +++ b/packages/rspack-test-tools/tests/hookCases/normalModuleFactory#afterResolve/resource/output.snap.txt @@ -10,11 +10,6 @@ module.exports = "a"; module.exports = "c"; -}), -"fs": (function (module) { -"use strict"; -module.exports = require("fs"); - }), }); @@ -80,21 +75,26 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { "use strict"; -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./a.js"); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_a__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./b.js"); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_b__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("fs"); -/* harmony import */var fs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_2__); + +// EXTERNAL MODULE: ./a.js +let a_ = __webpack_require__("./a.js"); +let a_default = /*#__PURE__*/__webpack_require__.n(a_); +// EXTERNAL MODULE: ./b.js +let b_ = __webpack_require__("./b.js"); +let b_default = /*#__PURE__*/__webpack_require__.n(b_); +;// CONCATENATED MODULE: external "fs" +var external_fs_namespaceObject = require("fs"); +let external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_namespaceObject); +;// CONCATENATED MODULE: ./resource.js it("should modify resource by after resolve hook", () => { - expect((_a__WEBPACK_IMPORTED_MODULE_0___default())).toBe("a"); - expect((_b__WEBPACK_IMPORTED_MODULE_1___default())).toBe("c"); + expect((a_default())).toBe("a"); + expect((b_default())).toBe("c"); const ext = ".js"; - expect(fs__WEBPACK_IMPORTED_MODULE_2___default().readFileSync(__filename, "utf-8")).toContain("./b" + ext); + expect(external_fs_default().readFileSync(__filename, "utf-8")).toContain("./b" + ext); }); })(); diff --git a/packages/rspack-test-tools/tests/statsAPICases/asset-info.js b/packages/rspack-test-tools/tests/statsAPICases/asset-info.js index bb5a2cd8218e..f06540940a87 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/asset-info.js +++ b/packages/rspack-test-tools/tests/statsAPICases/asset-info.js @@ -1,35 +1,35 @@ /** @type {import('../..').TStatsAPICaseConfig} */ module.exports = { - description: "should generate asset info", - options(context) { - return { - devtool: "source-map", - context: context.getSource(), - optimization: { - minimize: false - }, - entry: { - main: "./fixtures/asset/index" - }, - output: {}, - module: { - rules: [ - { - test: /\.png/, - type: "asset/resource" - } - ] - } - }; - }, - async check(stats) { - const statsOptions = { - all: true, - timings: false, - builtAt: false, - version: false - }; - expect(stats?.toJson(statsOptions).assets).toMatchInlineSnapshot(` + description: "should generate asset info", + options(context) { + return { + devtool: "source-map", + context: context.getSource(), + optimization: { + minimize: false + }, + entry: { + main: "./fixtures/asset/index" + }, + output: {}, + module: { + rules: [ + { + test: /\.png/, + type: "asset/resource" + } + ] + } + }; + }, + async check(stats) { + const statsOptions = { + all: true, + timings: false, + builtAt: false, + version: false + }; + expect(stats?.toJson(statsOptions).assets).toMatchInlineSnapshot(` Array [ Object { "chunkNames": Array [ @@ -78,10 +78,10 @@ module.exports = { }, }, "name": "main.js", - "size": 2597, + "size": 2455, "type": "asset", }, ] `); - } + } }; diff --git a/packages/rspack-test-tools/tests/statsAPICases/basic.js b/packages/rspack-test-tools/tests/statsAPICases/basic.js index 258b228ce15f..240b52566f34 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/basic.js +++ b/packages/rspack-test-tools/tests/statsAPICases/basic.js @@ -28,12 +28,14 @@ module.exports = { [no exports] [used exports unknown] Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2 + ModuleConcatenation bailout: Module is not an ECMAScript module entry ./fixtures/a cjs self exports reference self [585] ./fixtures/a.js [585] 55 bytes {909} [depth 0] [built] [code generated] [no exports] [used exports unknown] Statement with side_effects in source code at ./fixtures/a.js:1:0-3:2 + ModuleConcatenation bailout: Module is not an ECMAScript module entry ./fixtures/a cjs self exports reference self [585] diff --git a/packages/rspack-test-tools/tests/statsAPICases/chunks.js b/packages/rspack-test-tools/tests/statsAPICases/chunks.js index 5e42af940fc9..417d474e7a59 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/chunks.js +++ b/packages/rspack-test-tools/tests/statsAPICases/chunks.js @@ -64,6 +64,7 @@ module.exports = { "nameForCondition": "/tests/fixtures/b.js", "optimizationBailout": Array [ "Statement with side_effects in source code at ./fixtures/b.js:1:0-3:2", + "ModuleConcatenation bailout: Module is not an ECMAScript module", ], "optional": false, "orphan": false, @@ -165,6 +166,7 @@ module.exports = { "nameForCondition": "/tests/fixtures/chunk-b.js", "optimizationBailout": Array [ "Statement with side_effects in source code at ./fixtures/chunk-b.js:1:0-3:2", + "ModuleConcatenation bailout: Module is not an ECMAScript module", ], "optional": false, "orphan": false, diff --git a/packages/rspack-test-tools/tests/statsAPICases/exports.js b/packages/rspack-test-tools/tests/statsAPICases/exports.js index c172b4049d69..4f222c1ff5f5 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/exports.js +++ b/packages/rspack-test-tools/tests/statsAPICases/exports.js @@ -24,21 +24,13 @@ module.exports = { expect(typeof stats?.hash).toBe("string"); expect(stats?.toJson(statsOptions)).toMatchSnapshot(); expect(stats?.toString(statsOptions)).toMatchInlineSnapshot(` - "asset main.js 761 bytes [emitted] (name: main) - Entrypoint main 761 bytes = main.js + "asset main.js 471 bytes [emitted] (name: main) + Entrypoint main 471 bytes = main.js + orphan modules 192 bytes [orphan] 4 modules runtime modules 677 bytes 3 modules - cacheable modules 192 bytes - ./fixtures/esm/abc.js 80 bytes [built] [code generated] - [no exports] - [no exports used] - ./fixtures/esm/a.js 37 bytes [built] [code generated] - [exports: a, default] - [only some exports used: a] - ./fixtures/esm/b.js 38 bytes [built] [code generated] - [exports: b, default] - [only some exports used: default] - ./fixtures/esm/c.js 37 bytes [built] [code generated] - [exports: c, default] + ./fixtures/esm/abc.js + 3 modules 192 bytes [code generated] + [no exports] + [no exports used] Rspack compiled successfully" `); } diff --git a/packages/rspack-test-tools/tests/statsAPICases/verbose-time.js b/packages/rspack-test-tools/tests/statsAPICases/verbose-time.js index f737c49d257d..c3fda3beac27 100644 --- a/packages/rspack-test-tools/tests/statsAPICases/verbose-time.js +++ b/packages/rspack-test-tools/tests/statsAPICases/verbose-time.js @@ -47,6 +47,12 @@ module.exports = { LOG from rspack.EnsureChunkConditionsPlugin ensure chunk conditions: X ms + LOG from rspack.ModuleConcatenationPlugin + select relevant modules: X ms + sort relevant modules: X ms + find modules to concatenate: X ms + sort concat configurations: X ms + LOG from rspack.RealContentHashPlugin hash to asset names: X ms diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index 46a42a8bea32..3e0f1c3ae690 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -933,9 +933,7 @@ const applyOptimizationDefaults = ( D(optimization, "runtimeChunk", false); D(optimization, "realContentHash", production); D(optimization, "minimize", production); - // IGNORE(optimization.concatenateModules): webpack sets this option as true by default when the mode is production, - // but rspack is in the experimental stage and sets it to false by default - D(optimization, "concatenateModules", false); + D(optimization, "concatenateModules", production); // IGNORE(optimization.minimizer): Rspack use `SwcJsMinimizerRspackPlugin` and `SwcCssMinimizerRspackPlugin` by default A(optimization, "minimizer", () => [ new SwcJsMinimizerRspackPlugin(), diff --git a/webpack-test/configCases/container/2-transitive-overriding/index.js b/webpack-test/configCases/container/2-transitive-overriding/index.js index 53398777b082..f7771726839d 100644 --- a/webpack-test/configCases/container/2-transitive-overriding/index.js +++ b/webpack-test/configCases/container/2-transitive-overriding/index.js @@ -27,7 +27,6 @@ it("should have good module ids", async () => { "./b.js", "./modules-from-remote.js", "./modules.js", - "./shared.js", // remove this line once concatenateModules is supported https://github.com/web-infra-dev/rspack/issues/3823 "webpack/container/entry/container-no-shared", "webpack/container/reference/container-with-shared", "webpack/container/remote/container-with-shared/b",