Home > Back-end >  What is the influence of number of files on the bundle size of a React Native application?
What is the influence of number of files on the bundle size of a React Native application?

Time:07-29

The objective of my React Native application is as small bundle size as possible. And while looking for ways to keep the bundle size small, I came across this article Folder Structure Styles

My question is does the number of js files have any influence on the bundle size. i.e., If I were to put a 20 lines of code in a single file(for example in index.js in the above example) as against 20 lines of code distributed in 4 files, will it affect the bundle size of the app. Because this issue is recurrent in other situations like in redux store if I could combine few reducers into a single file, or is the effect negligible?. I'm predefining code access and ease of maintenance as much lower priority than the app bundle size. Thank you.

CodePudding user response:

No, it won't. React Native generates a bundle from all your code which translates into one single file and it is well optimized for this problem.

You can use this visualizer to see what is taking space: https://github.com/IjzerenHein/react-native-bundle-visualizer

The biggest issue most apps have regarding bundle size is not taking care of their dependencies. Coding everything in one file yourself will only hurt developer experience and maintainability.

  • Related