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?
react-native or more specifically, the metro-bundler that comes with react-native by default doesn't support tree-shaking.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With