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

[@rollup/plugin-json] Add functionality to transform object literal to JSON.parse("...") #1754

Open
DexterHill0 opened this issue Aug 5, 2024 · 0 comments

Comments

@DexterHill0
Copy link

  • Rollup Plugin Name: plugin-json

Feature Use Case

As stated by Vite:

imported JSON will be transformed into export default JSON.parse("...") which is significantly more performant than Object literals, especially when the JSON file is large.

and this (rollup-plugin-json-parse) very old plugin, in certain cases especially with large json blobs, export JSON.parse("...") is significantly faster than exporting an object literal.

This functionality is already built into Vite by specifying json.stringify. The logic behind this is extrememly simple and seems fit to be added to the rollup plugin without causing any issues. Perhaps it could even have an option that would transform the object literals to strings if the json is detected to be over a certain size.

Feature Proposal

The plugin config would take an extra option stringify that returns JSON.parse("...") instead of being converted into an object literal. A further stringifySize (or other name) could take a size that, if exceeded, would automatically remove the object literal.

I would be willing to add this functionality if desired.

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

No branches or pull requests

1 participant