What is metro bundler in react-native?

前端 未结 3 2100
醉酒成梦
醉酒成梦 2020-12-15 03:24

I am learning React Native.

I can\'t find a proper documentation for metro bundler. So, I have few questions on it. As the name suggest it creates a bundle.

3条回答
  •  Happy的楠姐
    2020-12-15 04:00

    Metro team keeps improving its documentation, now you can find some really good explanations at https://facebook.github.io/metro/docs/concepts (link updated):

    Metro is a JavaScript bundler. It takes in an entry file and various options, and gives you back a single JavaScript file that includes all your code and its dependencies.

    So yes, it is a sort of Webpack, but for React Native apps :)

    But where is the bundle file located?

    Once the bundler is started, you can check its contents at http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false (like webpack, it is served from memory, so it is not being written on your project's folder).

    What is the use of that bundle file ?

    This file is installed in the device for its code to be executed there. Remember that when you are writing code for a React Native application, your code is not "translated" to Java / Swift / whatever. The Native Modules will send events to a Javascript thread, and the JS thread will execute your bundled React Native code.

提交回复
热议问题