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(json): only add RuntimeGlobals::MODULE for concatenation #8126

Merged
merged 1 commit into from
Oct 15, 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
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
Loading