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

Allow .asset.json files to be treated as assets #1391

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bradleyayers
Copy link

@bradleyayers bradleyayers commented Nov 18, 2024

Summary

This patch in conjunction with adding asset.json to assetExts allows JSON files to be treated as assets. This is helpful in cases where the JSON file is large and would cause too much bloat in the main bundle.

Perhaps because json was previously in the assetExts array (removed in #593) it was necessary to have a special code path for transforming .json files rather than letting standard asset transformation take priority. However this logic prevents large JSON files from being treated as assets (i.e. not included in the bundle) even when using a custom extension like .asset.json. There is a test for asset.json that hints this should be supported, but the transform prevents it from working in practice (see

assetExts: new Set(['asset.json']),
).

Edit: After experimenting with this more, I found that in my use-case using async imports like import("./foo.json") instead works and splits the .json file out into another bundle. With that strategy this PR isn't necessary, so perhaps it's better to just close this.

Changelog:

Test plan

This patch in conjunction with adding `asset.json` to `assetExts` allows JSON files to be treated as assets. This is helpful in cases where the JSON file is large and would cause too much bloat in the main bundle.

Perhaps because `json` was previously in the `assetExts` array (removed in facebook#593) it was necessary to have a special code path for transforming `.json` files rather than letting standard asset transformation take priority. However this logic prevents large JSON files from being treated as assets (i.e. not included in the bundle) even when using a custom extension like `.asset.json`. There is a test for `asset.json` that hints this should be supported, but the transform prevents it from working in practice (see https://github.com/facebook/metro/blob/412771475c540b6f85d75d9dcd5a39a6e0753582/packages/metro-resolver/src/__tests__/assets-test.js#L67).
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants