My ReactNative Journey - 2 - Understanding the folder contents
Understanding the folder structure and the files in it.
React native is a platform on which we can make both Android and IOS apps with a single code structure How does it do it? We will try and make sense of what is happening behind the scenes. To start with, react native CLI creates the following files/directories in the project folder, when it creates a project:
- _tests_ - Testing Support
src/file.test.js
mentioned first in the Getting Started docs, and is great for keeping tests (especially unit) easy to find next to source filessrc/__tests__/file.test.js
lets you have multiple__tests__
directories so tests are still near original files without cluttering the same directories__tests__/file.test.js
more like older test frameworks that put all the tests in a separate directory; while Jest does support it, it's not as easy to keep tests organized and discoverable
Reference Sites and More Info here: Jest is a JavaScript test runner, that is, a JavaScript library for creating, running, and structuring tests. Jest ships as an NPM package, you can install it in any JavaScript project. Jest is one of the most popular test runner these days, and the default choice for React projects
- .vscode - created by vscode for its own purposes
- android - created for running code on android.
- ios - created for running code on iOS
- node_modules - created for keeping node libraries.
- .buckconfig - The root of your project must contain a configuration file named
.buckconfig
. Before executing, Buck reads this file to incorporate any customizations it specifies. More information here I am not sure at this time if or how buck is being used in this project. Will come back to this later maybe. - .flowconfig - Flow is a framework that, like TypeScript, promotes static typing in JavaScript. And like TypeScript it ships with React Native without any issues. It lets you annotate the variables, functions, and React components with a special type syntax, and catch mistakes early. More on this here
- .gitattributes
- .gitignore
- .eslintrc.js - ESLint helps us write a better code by checking if our code is well written, well-formatted, and respects some rules defined as the best practices for maintainable and consistent code.It is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, with the goal of making code more consistent and avoiding bugs. In many ways, it is similar to JSLint and JSHint with a few exceptions:
- ESLint uses Espree for JavaScript parsing.
- ESLint uses an AST to evaluate patterns in code.
- ESLint is completely pluggable, every single rule is a plugin and you can add more at runtime.
- .prettierc.js - Prettier is a code style formatter, different from ESLint, Prettier only formats the code style, and does not look for syntax problems.
Rules like
max-len, no-mixed-spaces-and-tabs, keyword-spacing, comma-style
are some popular formatting rules in Prettier, and rules like no-unused-vars, no-extra-bind,
no=implicit-globals, prefer-promise-reject-errors
are common rules in ESLint.Reference Sites and More information here: https://eslint.org/docs/user-guide/getting-started and here: https://blog.devgenius.io/eslint-prettier-typescript-and-react-in-2022-e5021ebca2b1
- .watchmanconfig - Watchman is a file watching service. It Watches files and records, or triggers actions, when they change. When watching a root, if a valid JSON file named
.watchmanconfig
is present in the root directory, watchman will load it and use it as a source of configuration information specific to that root.
- App.js - The entry point for our code. This is where we do all of our programming.
- app.json - typically it is imported in index.js to get the name for the root component: https://github.com/facebook/react-native/blob/44beb2a685b7ceb0311bde7d0d33cb70bb891d30/template/index.js#L7. Here is some interesting history of app.json and whether it is really required - https://github.com/react-native-community/cli/issues/1113
- babel.config.js - Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments. Here are the main things Babel can do for you:
- index.js - This is the starting point for React Native applications, and it is always required. It can be a small file that require s other file that are part of your React Native component or application, or it can contain all the code that is needed for it.
- metro.config.js - Every time you run a react native project, many javascript files are compiled into a single JS file. This compilation is done by a bundler called Metro. The metro.config.js file provides Metro with all the information it needs to do its job.
- package.json - automatically maintains all module dependencies along with version numbers. This is useful if you happen to lose some of your dependencies.
- yarn.lock - Autogenerated file, used by Yarn
So, there you are, an extremely brief glimpse on the files and folders that form the eco-system of a React Native Project. Good Luck from here.
Comments
Post a Comment