Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does React Native perform Tree Shaking?

Tags:

react-native

I am trying to weigh up the benefits of converting moment to date-fns.

Moment is currently 316k or 67.6k gzipped.

date-fns/format is 3k.

We deliver updates through CodePush so minimising the JavaScript bundle is something that we need to definitely think about doing.

Does React-Native perform Tree Shaking?

like image 895
Dan Avatar asked May 10 '18 11:05

Dan


People also ask

Does React Native have tree shaking?

react-native or more specifically, the metro-bundler that comes with react-native by default doesn't support tree-shaking.

Does react shake tree?

In order to implement tree shaking in react application you will need to have a module bundler that will bundle the entire app's code. You can either use WebPack or RollUp for bundling your application.

Does lodash support tree shaking?

If you're already using Babel, the easiest method to properly tree shake lodash is to use the official babel-plugin-lodash by the lodash team. This uses Babel to rewrite your lodash imports into a more tree-shakeable form.

How does a shaking tree work?

Tree shaking is a term commonly used within a JavaScript context to describe the removal of dead code. It relies on the import and export statements to detect if code modules are exported and imported for use between JavaScript files.


1 Answers

react-native or more specifically, the metro-bundler that comes with react-native by default doesn't support tree-shaking.

Tree-shaking issue was closed. You could find their motivation here.

like image 174
fbartho Avatar answered Sep 17 '22 17:09

fbartho