Skip to content

Commit

Permalink
fix(json): only add RuntimeGlobals::MODULE for concatenation (#8126)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored Oct 15, 2024
1 parent 45c0b20 commit 4ea491e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions crates/rspack_plugin_json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ impl ParserAndGenerator for JsonParserAndGenerator {
let module_graph = compilation.get_module_graph();
match generate_context.requested_source_type {
SourceType::JavaScript => {
generate_context
.runtime_requirements
.insert(RuntimeGlobals::MODULE);
let module = module_graph
.module_by_identifier(&module.identifier())
.expect("should have module identifier");
Expand Down Expand Up @@ -184,6 +181,9 @@ impl ParserAndGenerator for JsonParserAndGenerator {
scope.register_namespace_export(NAMESPACE_OBJECT_EXPORT);
format!("var {NAMESPACE_OBJECT_EXPORT} = {json_expr}")
} else {
generate_context
.runtime_requirements
.insert(RuntimeGlobals::MODULE);
format!(r#"module.exports = {}"#, json_expr)
};
Ok(RawSource::from(content).boxed())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ chunk (runtime: main) trees.js (trees) 215 bytes [rendered]
`;

exports[`StatsTestCases should print correct stats for ignore-warnings 1`] = `
"asset main.js 1.83 KiB [emitted] (name: main)
"asset main.js 928 bytes [emitted] (name: main)
orphan modules 794 bytes [orphan] 10 modules
./index.js + 9 modules 794 bytes [code generated]
Rspack x.x.x compiled successfully in X.23"
Expand Down

2 comments on commit 4ea491e

@rspack-bot
Copy link

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 (2024-10-15 25af140) Current Change
10000_development-mode + exec 2.12 s ± 39 ms 2.11 s ± 34 ms -0.49 %
10000_development-mode_hmr + exec 665 ms ± 22 ms 664 ms ± 26 ms -0.05 %
10000_production-mode + exec 2.65 s ± 33 ms 2.64 s ± 37 ms -0.09 %
arco-pro_development-mode + exec 1.82 s ± 87 ms 1.79 s ± 59 ms -1.59 %
arco-pro_development-mode_hmr + exec 426 ms ± 1.9 ms 426 ms ± 1.2 ms +0.06 %
arco-pro_production-mode + exec 3.04 s ± 65 ms 3.08 s ± 51 ms +1.18 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.15 s ± 70 ms 3.1 s ± 65 ms -1.41 %
threejs_development-mode_10x + exec 1.64 s ± 15 ms 1.61 s ± 8.4 ms -1.70 %
threejs_development-mode_10x_hmr + exec 788 ms ± 11 ms 755 ms ± 13 ms -4.25 %
threejs_production-mode_10x + exec 4.97 s ± 28 ms 4.9 s ± 27 ms -1.45 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
rspress ✅ success
rslib ✅ success
rsbuild ✅ success
examples ✅ success
devserver ❌ failure

Please sign in to comment.