Skip to content

Conversation

@colinaaa
Copy link
Contributor

For large .json modules, webpack will generate JSON.parse by default for
better performance. But there are some circumstances that JSON.parse is not a
good choice (e.g.: when doing AOT compilation).

Thus, a new generator option module.generator.json.JSONParse is added to
disable generating JSON.parse for .json module.

The default value is kept as true and can be opt-out by custom rules.

fix: #19319

What kind of change does this PR introduce?

feature

Did you add tests for your changes?

yes

Does this PR introduce a breaking change?

no

What needs to be documented once your changes are merged?

The new option should be documented https://webpack.js.org/configuration/module/#modulegenerator

For large `.json` modules, webpack will generate `JSON.parse` by default for
better performance. But there are some circumstances that `JSON.parse` is not a
good choice (e.g.: when doing AOT compilation).

Thus, a new generator option `module.generator.json.JSONParse` is added to
disable generating `JSON.parse` for `.json` module.

The default value is kept as `true` and can be opt-out by custom rules.

fix: webpack#19319
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 13, 2025

CLA Signed


The committers listed above are authorized under a signed CLA.

@alexander-akait alexander-akait merged commit 48ffd14 into webpack:main Mar 13, 2025
58 of 63 checks passed
colinaaa added a commit to colinaaa/rspack that referenced this pull request Mar 13, 2025
For large `.json` modules, webpack will generate `JSON.parse` by default for
better performance. But there are some circumstances that `JSON.parse` is not a
good choice (e.g.: when doing AOT compilation).

Thus, a new generator option `module.generator.json.JSONParse` is added to
disable generating `JSON.parse` for `.json` module.

The default value is kept as `true` and can be opt-out by custom rules.

This is a port of webpack/webpack#19320.
ahabhgk pushed a commit to web-infra-dev/rspack that referenced this pull request Mar 14, 2025
For large `.json` modules, webpack will generate `JSON.parse` by default for
better performance. But there are some circumstances that `JSON.parse` is not a
good choice (e.g.: when doing AOT compilation).

Thus, a new generator option `module.generator.json.JSONParse` is added to
disable generating `JSON.parse` for `.json` module.

The default value is kept as `true` and can be opt-out by custom rules.

This is a port of webpack/webpack#19320.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a JSON generator option to avoid JSON.parse

2 participants