Skip to content

Commit

Permalink
fix(modern-module): skip the asset entry module concaten for Rslib (#…
Browse files Browse the repository at this point in the history
…8837)

* chore: update

* chore: update

* chore: update snap
  • Loading branch information
SoonIter authored Jan 2, 2025
1 parent 96084cc commit e768650
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
13 changes: 12 additions & 1 deletion crates/rspack_plugin_library/src/modern_module_library_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rspack_core::{
CodeGenerationExportsFinalNames, Compilation, CompilationFinishModules,
CompilationOptimizeChunkModules, CompilationParams, CompilerCompilation, CompilerOptions,
ConcatenatedModule, ConcatenatedModuleExportsDefinitions, DependenciesBlock, Dependency,
DependencyId, LibraryOptions, ModuleGraph, ModuleIdentifier, Plugin, PluginContext,
DependencyId, LibraryOptions, ModuleGraph, ModuleIdentifier, Plugin, PluginContext, SourceType,
};
use rspack_error::{error_bail, Result};
use rspack_hash::RspackHash;
Expand Down Expand Up @@ -113,6 +113,17 @@ impl ModernModuleLibraryPlugin {
.collect::<HashSet<_>>();

for module_id in unconcatenated_module_ids.into_iter() {
// skip the asset module when the entry is asset module
let module_graph = compilation.get_module_graph();
let Some(module) = module_graph.module_by_identifier(module_id) else {
continue;
};
let source_types = module.source_types();
let is_asset_module = source_types.contains(&SourceType::Asset);
if is_asset_module {
continue;
}

let chunk_runtime = compilation
.chunk_graph
.get_module_runtimes(*module_id, &compilation.chunk_by_ukey)
Expand Down
45 changes: 45 additions & 0 deletions packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,51 @@ const a = 'a'
export { a };
`;
exports[`config config/library/modern-module-force-concaten step should pass: asset as entry should not be concatenated 1`] = `
var __webpack_modules__ = ({
"273": (function (module, __unused_webpack_exports, __webpack_require__) {
module.exports = __webpack_require__.p + "fc90103f80b6abc6.png";
}),
});
/************************************************************************/
// The module cache
var __webpack_module_cache__ = {};
// The require function
function __webpack_require__(moduleId) {
// Check if module is in cache
var cachedModule = __webpack_module_cache__[moduleId];
if (cachedModule !== undefined) {
return cachedModule.exports;
}
// Create a new module (and put it into the cache)
var module = (__webpack_module_cache__[moduleId] = {
exports: {}
});
// Execute the module function
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
// Return the exports of the module
return module.exports;
}
/************************************************************************/
// webpack/runtime/public_path
(() => {
__webpack_require__.p = "";
})();
/************************************************************************/
// startup
// Load entry module and return exports
// This entry module doesn't tell about it's top-level declarations so it can't be inlined
var __webpack_exports__ = __webpack_require__("273");
`;
exports[`config config/library/modern-module-force-concaten step should pass: external module should bail out when bundling 1`] = `
import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "node:module";
var __webpack_modules__ = ({
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ module.exports = {
"d": "./d.mjs",
"e": "./e/index.js",
"f": "./f/index.js",
"g": "./g/index.js"
"g": "./g/index.js",
"h": "./h/file.png",
},
module: {
rules: [
{
test: /\.png$/,
type: "asset/resource",
}
]
},
externals: {
path: 'node-commonjs path',
Expand Down Expand Up @@ -42,6 +51,7 @@ module.exports = {
expect(assets['e.js']._value).toMatchSnapshot(".cjs should bail out when bundling");
expect(assets['f.js']._value).toMatchSnapshot("external module should bail out when bundling");
expect(assets['g.js']._value).toMatchSnapshot("harmony export should concat, even with bailout reason");
expect(assets['h.js']._value).toMatchSnapshot("asset as entry should not be concatenated");
});
};
this.hooks.compilation.tap("testcase", handler);
Expand Down

1 comment on commit e768650

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on e768650 Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2025-01-02 9a00d39) Current Change
10000_big_production-mode_disable-minimize + exec 37.3 s ± 234 ms 37.7 s ± 638 ms +1.04 %
10000_development-mode + exec 1.88 s ± 30 ms 1.81 s ± 25 ms -3.69 %
10000_development-mode_hmr + exec 680 ms ± 6.9 ms 685 ms ± 38 ms +0.76 %
10000_production-mode + exec 2.5 s ± 44 ms 2.49 s ± 75 ms -0.36 %
arco-pro_development-mode + exec 1.73 s ± 89 ms 1.72 s ± 60 ms -0.39 %
arco-pro_development-mode_hmr + exec 377 ms ± 2.7 ms 377 ms ± 0.8 ms -0.07 %
arco-pro_production-mode + exec 3.64 s ± 92 ms 3.55 s ± 65 ms -2.38 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.67 s ± 155 ms 3.61 s ± 78 ms -1.51 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.66 s ± 128 ms 3.57 s ± 101 ms -2.55 %
threejs_development-mode_10x + exec 1.52 s ± 22 ms 1.5 s ± 29 ms -1.22 %
threejs_development-mode_10x_hmr + exec 787 ms ± 34 ms 769 ms ± 18 ms -2.30 %
threejs_production-mode_10x + exec 5.37 s ± 95 ms 5.4 s ± 153 ms +0.57 %
10000_big_production-mode_disable-minimize + rss memory 9465 MiB ± 98.4 MiB 9520 MiB ± 28.3 MiB +0.58 %
10000_development-mode + rss memory 659 MiB ± 13.5 MiB 689 MiB ± 23.7 MiB +4.48 %
10000_development-mode_hmr + rss memory 1426 MiB ± 352 MiB 1506 MiB ± 252 MiB +5.62 %
10000_production-mode + rss memory 629 MiB ± 21.3 MiB 670 MiB ± 38.9 MiB +6.43 %
arco-pro_development-mode + rss memory 576 MiB ± 25.9 MiB 586 MiB ± 45.3 MiB +1.71 %
arco-pro_development-mode_hmr + rss memory 624 MiB ± 42 MiB 631 MiB ± 49.3 MiB +1.02 %
arco-pro_production-mode + rss memory 743 MiB ± 64.5 MiB 739 MiB ± 51.5 MiB -0.56 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 743 MiB ± 39.9 MiB 761 MiB ± 45.1 MiB +2.46 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 751 MiB ± 51.1 MiB 750 MiB ± 58.5 MiB -0.12 %
threejs_development-mode_10x + rss memory 613 MiB ± 23.4 MiB 623 MiB ± 28.8 MiB +1.61 %
threejs_development-mode_10x_hmr + rss memory 1175 MiB ± 68.7 MiB 1084 MiB ± 155 MiB -7.72 %
threejs_production-mode_10x + rss memory 857 MiB ± 44.9 MiB 917 MiB ± 48.5 MiB +6.99 %

Please sign in to comment.