feat: implement module.generator.json.JSONParse#9666
Merged
ahabhgk merged 2 commits intoweb-infra-dev:mainfrom Mar 14, 2025
Merged
feat: implement module.generator.json.JSONParse#9666ahabhgk merged 2 commits intoweb-infra-dev:mainfrom
module.generator.json.JSONParse#9666ahabhgk merged 2 commits intoweb-infra-dev:mainfrom
Conversation
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.
✅ Deploy Preview for rspack canceled.Built without sensitive environment variables
|
CodSpeed Performance ReportMerging #9666 will not alter performanceComparing 🎉 Hooray!
|
KuSh
reviewed
Mar 13, 2025
Contributor
KuSh
left a comment
There was a problem hiding this comment.
Why not integrating associated webpack tests to the suite?
ahabhgk
previously approved these changes
Mar 14, 2025
ahabhgk
reviewed
Mar 14, 2025
packages/rspack-test-tools/tests/configCases/json/generator-json-parse-false/index.js
Show resolved
Hide resolved
ahabhgk
approved these changes
Mar 14, 2025
2 tasks
github-merge-queue bot
pushed a commit
to lynx-family/lynx-stack
that referenced
this pull request
Jul 15, 2025
<!-- Thank you for submitting a pull request! We appreciate the time and effort you have invested in making these changes. Please ensure that you provide enough information to allow others to review your pull request. Upon submission, your pull request will be automatically assigned with reviewers. If you want to learn more about contributing to this project, please visit: https://github.com/lynx-family/lynx-stack/blob/main/CONTRIBUTING.md. --> ## Summary <!-- Can you explain the reasoning behind implementing this change? What problem or issue does this pull request resolve? --> <!-- It would be helpful if you could provide any relevant context, such as GitHub issues or related discussions. --> In web-infra-dev/rspack#9666, we added `module.generator.json.JSONParse` and set `JSONParse: false` for the main thread only to let AOT compilation speed up performance. However, different `JSONParse` configurations in the main thread and the background thread will prevent `extractStr` from working properly. In this PR, when `extractStr` is enabled, we should set `JSONParse` to `false` in both the main and background threads. ## Checklist <!--- Check and mark with an "x" --> - [x] Tests updated (or not required). - [ ] Documentation updated (or not required). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for the `extractStr` feature to improve handling of large JSON data. * **Bug Fixes** * Adjusted JSON processing rules to ensure correct behavior when `extractStr` is enabled or disabled. * **Tests** * Enhanced and added tests to verify JSON generator rule behavior across different plugin configurations and layers. * **Documentation** * Updated documentation to reflect the new feature and changes in behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
For large
.jsonmodules, webpack will generateJSON.parseby default forbetter performance. But there are some circumstances that
JSON.parseis not agood choice (e.g.: when doing AOT compilation).
Thus, a new generator option
module.generator.json.JSONParseis added todisable generating
JSON.parsefor.jsonmodule.The default value is kept as
trueand can be opt-out by custom rules.This is a port of webpack/webpack#19320.
Checklist