Skip to content

Commit

Permalink
fix(json): only add RuntimeGlobals::MODULE for concatenation (web-inf…
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

0 comments on commit 4ea491e

Please sign in to comment.