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

FR: tree shake JSON imports #4000

Open
Conaclos opened this issue Dec 9, 2024 · 0 comments
Open

FR: tree shake JSON imports #4000

Conaclos opened this issue Dec 9, 2024 · 0 comments

Comments

@Conaclos
Copy link

Conaclos commented Dec 9, 2024

As indicated in the ESBuild documentation, ESbuild is able to tree shake a JSON import when we use named imports.
Unfortunately, named imports for JSON files are now an outdated feature in JS engines.
A JSON file must now be imported as a default import and with an import attribute.

ESbuild could recognize standard JSON imports and tree shake them.

Given the following code:

import packageJson from "./package.json" with { type: "json" };
export const VERSION = packageJson.version;

And assuming that version is set to 1.0.0 in package.json, ESbuild could output the following bundled code:

export const VERSION = "1.0.0";
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