-
Notifications
You must be signed in to change notification settings - Fork 626
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
Remove JSON from default asset types #593
Conversation
JSON files are currently considered both source and assets so they are duplicated in the js bundle and in the assets copied in the final app. I think this is a better default and if someone relies on json files being also included in the bundle they can add it back in their metro config. Fixes facebook#487
We actually rely on this at FB as we access JSON files from native 🤔 |
Hmm so native looks for the file in assets and relies on RN to bundle it? Seems like quite the hack, but I don't see another easy way for native to access it without JS sending it though the bridge. Do you think it'd be possible to update the facebook metro config to add back JSON in asset types and remove it from the default OSS config? |
Yeah we may be able to do that, I can take a look. It may sound hacky but it allows us to do a ton of work in native to preload stuff instead of initializing a JS VM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpojer has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
The static JSON file assets are not the sourced by the app. Instead, the data found within the JavaScript bundle itself is utilized. The unnecessary static JSON files should now no longer be exported when bundling the JavaScript thanks to a bug fix in React Native. - #4329 (comment) - facebook/metro#593
The static JSON file assets are not the sourced by the app. Instead, the data found within the JavaScript bundle itself is utilized. The unnecessary static JSON files should now no longer be exported when bundling the JavaScript thanks to a bug fix in React Native. - #4329 (comment) - facebook/metro#593
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).
Summary
JSON files are currently considered both source and assets so they are duplicated in the js bundle and in the assets copied in the final app. I think this is a better default and if someone relies on json files being also included in the bundle they can add it back in their metro config.
Fixes #487
Test plan
Test that json files are no longer present in my app assets and the app still works.