Search code examples
javascriptandroidreact-nativeoptimizationuglifyjs

Does react-native optimize JavaScript code?


I read a guide on compilers. They have many optimization techniques like removing redundant code or removing unused variables and none used methods.
But script languages like javascript don't have compiler, so take it will not have optimizations.
I read a article about js optimizer like:

- Google Closure Compiler https://github.com/google/closure-compiler
- UglifyJS https://github.com/mishoo/UglifyJS

And the real question is Does platforms like react-native, angular, use code optimizer or should I use it myself?


Solution

  • The React Native script bundler, Metro, first transpiles your code using Babel. In production build mode, it then runs your code through UglifyJS.

    The default configuration doesn't do any advanced optimizations such as tree-shaking or deduping.

    If you want to apply more advanced optimizations, you can try to see if they can be achieved during the transpilation step using Babel plugins. If not, it may be easiest to use Haul, a webpack-based alternative bundler for React Native.

    However, as always, before optimizing prematurely, think about what metrics you are trying to improve and measure whether your optimizations actually achieve your goals.