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

Remove JSON from default asset types #593

Closed
wants to merge 2 commits into from

Conversation

janicduplessis
Copy link
Contributor

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.

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
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 6, 2020
@cpojer
Copy link
Contributor

cpojer commented Nov 11, 2020

We actually rely on this at FB as we access JSON files from native 🤔

@janicduplessis
Copy link
Contributor Author

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?

@cpojer
Copy link
Contributor

cpojer commented Nov 11, 2020

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.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

@facebook-github-bot
Copy link
Contributor

@cpojer merged this pull request in 279f04f.

dcalhoun added a commit to wordpress-mobile/gutenberg-mobile that referenced this pull request Dec 22, 2021
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
dcalhoun added a commit to wordpress-mobile/gutenberg-mobile that referenced this pull request Jan 24, 2022
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
bradleyayers added a commit to bradleyayers/metro that referenced this pull request Nov 18, 2024
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).
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. Merged
Projects
None yet
3 participants