Allow .asset.json files to be treated as assets #1391
+6
−6
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
This patch in conjunction with adding
asset.json
toassetExts
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 theassetExts
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 forasset.json
that hints this should be supported, but the transform prevents it from working in practice (seemetro/packages/metro-resolver/src/__tests__/assets-test.js
Line 67 in 4127714
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