All Projects โ†’ nitishdayal โ†’ Cra_closer_look

nitishdayal / Cra_closer_look

An explanation of the problems that Create-React-App addresses, and how it attempts to solve them.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Cra closer look

Simpler Paper
elegant document generation tool.
Stars: โœญ 151 (-5.03%)
Mutual labels:  documentation
Pandas Doc Zh
๐Ÿ“– [่ฏ‘] Pandas ไธญๆ–‡ๆ–‡ๆกฃ๏ผˆๅพ…ๆ กๅฏน๏ผ‰
Stars: โœญ 155 (-2.52%)
Mutual labels:  documentation
Mm Wiki
MM-Wiki ไธ€ไธช่ฝป้‡็บง็š„ไผไธš็Ÿฅ่ฏ†ๅˆ†ไบซไธŽๅ›ข้˜ŸๅๅŒ่ฝฏไปถ๏ผŒๅฏ็”จไบŽๅฟซ้€Ÿๆž„ๅปบไผไธš Wiki ๅ’Œๅ›ข้˜Ÿ็Ÿฅ่ฏ†ๅˆ†ไบซๅนณๅฐใ€‚้ƒจ็ฝฒๆ–นไพฟ๏ผŒไฝฟ็”จ็ฎ€ๅ•๏ผŒๅธฎๅŠฉๅ›ข้˜Ÿๆž„ๅปบไธ€ไธชไฟกๆฏๅ…ฑไบซใ€ๆ–‡ๆกฃ็ฎก็†็š„ๅไฝœ็Žฏๅขƒใ€‚
Stars: โœญ 2,364 (+1386.79%)
Mutual labels:  documentation
React Admin
ๅŸบไบŽ[emailย protected]็š„reactๅŠจๆ€ๆƒ้™ๅŽๅฐ็ฎก็†็ณป็ปŸๆจกๆฟ
Stars: โœญ 151 (-5.03%)
Mutual labels:  create-react-app
Docs.easyjitsi.com
๐Ÿ“– Learn About Jitsi & Take your Product to the Next Level With Easy Jitsi
Stars: โœญ 155 (-2.52%)
Mutual labels:  documentation
Jsdoc
An API documentation generator for JavaScript.
Stars: โœญ 12,555 (+7796.23%)
Mutual labels:  documentation
Generator Standard Readme
Scaffold out a Standard Readme
Stars: โœญ 150 (-5.66%)
Mutual labels:  documentation
Eth Ipfs
etherum + ipfs + react
Stars: โœญ 159 (+0%)
Mutual labels:  create-react-app
Express Typescript Boilerplate
A delightful way to building a RESTful API with NodeJs & TypeScript by @w3tecch
Stars: โœญ 2,293 (+1342.14%)
Mutual labels:  documentation
Pandocs
The infamous Pan Docs historical document: the single, most comprehensive Game Boy technical reference.
Stars: โœญ 158 (-0.63%)
Mutual labels:  documentation
Pepp Pt Documentation
Documentation for Pan-European Privacy-Preserving Proximity Tracing (PEPP-PT)
Stars: โœญ 153 (-3.77%)
Mutual labels:  documentation
Nasa Latex Docs
An easy and convenient package to create technical LaTeX documents.
Stars: โœญ 153 (-3.77%)
Mutual labels:  documentation
Mkdocs
Project documentation with Markdown.
Stars: โœญ 13,346 (+8293.71%)
Mutual labels:  documentation
Typemill
TYPEMILL is a simple and lightweight Flat-File-CMS for authors and publishers.
Stars: โœญ 150 (-5.66%)
Mutual labels:  documentation
Cra Recipe
Step-by-step guide to bootstrap a CRA app from scratch.
Stars: โœญ 158 (-0.63%)
Mutual labels:  create-react-app
Ebook Template
Template to create PDF, ePub and Kindle books with Asciidoctor
Stars: โœญ 150 (-5.66%)
Mutual labels:  documentation
Home Assistant.io
๐Ÿ“˜ Home Assistant User documentation
Stars: โœญ 2,377 (+1394.97%)
Mutual labels:  documentation
React App Rewire Styled Components
Add the styled-components Babel plugin to your create-react-app app via react-app-rewired
Stars: โœญ 159 (+0%)
Mutual labels:  create-react-app
Awesome Pharo
A collection of awesome Pharo libraries, tools, frameworks and software.
Stars: โœญ 159 (+0%)
Mutual labels:  documentation
Documentation
Pantheon Docs
Stars: โœญ 157 (-1.26%)
Mutual labels:  documentation

Create-React-App: A Closer Look

Nitish Dayal
Last Commit Date: May 15th, 2017

About

The purpose of this document is to provide an overview of the problem/s Create-React-App attempts to solve, and how that solution is implemented. It will walk through the flow of using Create-React-App and provide insight into what each of the provided scripts do, with the intention of explaining what's happening 'behind-the-scenes' with Create-React-App. This document does not hold any information about customizing the scripts, the actual configurations for the various tools put into use by Create-React-App, or information regarding how to use those tools.

We will use the Tic-Tac-Toe project from the Intro To React tutorial as a starting point. The components have been split into separate files, and the calculateWinner function lives in the utils folder as a utility function. The source code can be found here. Feel free to clone the project and follow along.

Introduction

The Problem

As single-page applications and the needs of our users have grown in complexity, so has the landscape of front-end development. Modern single-page applications can consist of multiple JS files communicating with one another in order to manipulate the DOM, reducing (and in some cases eliminating) the need to request files from a server to update an application's UI. To allow for these JavaScript files, or modules, to interact efficiently in the browser, one option is to take advantage of a module bundler. A module bundler will parse through our code, mapping out dependencies as it comes across them, to bundle our application together in a way that the browser can understand, while still allowing developers to maintain modularity and separation in the codebase.

Some React developers write their applications using ES2015+ to utilize the benefits provided by the latest JavaScript syntax. However, browser support for changes to the JavaScript language are inconsistent at best, and we want users of our applications to have the same experience regardless of their browser choice. To ensure that our applications will run consistently and smoothly across browsers, we need to transpile our code from ES2015 down to a version of JavaScript that has better support across popular browsers.

Given that JavaScript can be fairly loose in terms of implementation it's beneficial to provide a set of rules and guidelines that application code must adhere to, as well as to provide a way to test your application against multiple scenarios and build on those tests as the application continues to grow. In order to enforce such guidelines, linters allow developers to set rules for how code should be written within the scope of their application, and will throw errors or warnings when those rules/guidelines aren't being followed. There are also many testing libraries, with variations in their approach to how an application is tested.

Implementing these tools into a project can be time consuming and overwhelming, especially if you're tasked with learning the tools while also learning a new library or framework. This creates a large 'barrier of entry' for those interested in React, but maybe lack experience working with these tools.

The Solution

Create-React-App provides a development environment with a selection of pre-configured tools to handle these needs, while providing some flexibility and customization options. Create-React-App also provides some convenience features, such as: a live development environment (intelligently updates your app in-browser as you modify your code), boilerplate code, and standard dependencies pre-installed. Developers can initiate applications via Create-React-App with confidence that the tools and configurations will allow them to take their application from development to deployment.

It also allows developers who are new to modern JavaScript tools/libraries to begin learning React without first having to decide how to set up their individual development environments and learn the necessary tools, effectively removing the barrier of entry.

Create-React-App Development Flow

Here is the directory structure of the example application found under tic-tac-toe. It is the end result of us using Create-React-App to generate the initial scaffolding, creating a folder utils/ under src/ (files necessary for the application should all be somewhere in under the src/ folder, or the public/ folder for static files).

Current Application Directory Structure:

โ”œโ”€โ”€ node_modules/     # Installed packages necessary for Create-React-App
โ”œโ”€โ”€ public/           # Static files
โ”‚   โ”œโ”€โ”€ favicon.ico
โ”‚   โ””โ”€โ”€ index.html
โ”œโ”€โ”€ src/              # Application root
โ”‚   โ”œโ”€โ”€ components/   # Application components
โ”‚   โ”‚   โ”œโ”€โ”€ board.js
โ”‚   โ”‚   โ”œโ”€โ”€ game.js
โ”‚   โ”‚   โ””โ”€โ”€ square.js
โ”‚   โ”œโ”€โ”€ index.css
โ”‚   โ”œโ”€โ”€ index.js
โ”‚   โ”œโ”€โ”€ logo.svg
โ”‚   โ””โ”€โ”€ utils/        # Utility files: tools (like a custom string formatting function) to be utilized in multiple parts of the application
โ”‚       โ””โ”€โ”€ index.js
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ yarn.lock

4 directories, 12 files

yarn start/npm start

Webpack (the module bundler used by CRA) parses through the application starting at src/index.js, following any imported modules, until it has a complete dependency graph. In order to convert the ES2015+ code that Webpack comes across into a version of JavaScript that will behave consistently across browsers, Webpack passes any JavaScript files it comes across through Babel. Babel is a transpiler which parses newer and experimental JavaScript syntax, and transforms the code into a version of JavaScript which has better support across browsers.

Webpack uses the generated dependency graph to create a single JavaScript file consisting of the application source code and modules used by the app, injects the file via script tag into public/index.html, and starts a development server on http://localhost:3000. Navigating to this URL in the browser will show a live, interactive instance of your application. Any changes saved to the source code will reflect in the running app instance automatically.

yarn test/npm run test

Create-React-App uses the Jest testing framework to handle unit testing. Running this command will start the test runner in 'watch' mode; as you make changes to your code the tests will rerun to ensure they continue to pass. To stop this script, press Ctrl+C while your terminal is selected as the active window.

Covering the Jest framework is well outside the scope of this document, and is already quite thoroughly documented on the official website. An introduction is available in the Running Tests section of the Create-React-App documentation.

yarn build/npm run build

Create-React-App will first ensure that the files src/index.js and public/index.html exist. These files can be modified as necessary, but the names and locations shouldn't be altered. It then calls on Webpack to create an optimized, production-ready bundle of the application. Aside from actually generating a new folder & files (build/**/*), the configuration provided to Webpack for this build differs from the one used during development. Some examples of these optimizations:

  • The bundle created from this configuration has the source code minified and compressed for performance benefits.

  • The source maps generated from this configuration are full SourceMap files (*.map.js) in comparison to the less-detailed, but faster to generate SourceMap files generated from the development configuration.

For details/instructions on deploying this build, see the Create-React-App documentation under Deployment.

Post-Build Directory Structure:

โ”œโ”€โ”€ build/
โ”‚   โ”œโ”€โ”€ asset-manifest.json
โ”‚   โ”œโ”€โ”€ favicon.ico
โ”‚   โ”œโ”€โ”€ index.html
โ”‚   โ””โ”€โ”€ static/
โ”‚       โ”œโ”€โ”€ css/
โ”‚       โ”‚   โ”œโ”€โ”€ main.09253d15.css
โ”‚       โ”‚   โ””โ”€โ”€ main.09253d15.css.map
โ”‚       โ””โ”€โ”€ js/
โ”‚           โ”œโ”€โ”€ main.c97b4c53.js
โ”‚           โ””โ”€โ”€ main.c97b4c53.js.map
โ”œโ”€โ”€ public/
โ”‚   โ”œโ”€โ”€ favicon.ico
โ”‚   โ””โ”€โ”€ index.html
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”œโ”€โ”€ board.js
โ”‚   โ”‚   โ”œโ”€โ”€ game.js
โ”‚   โ”‚   โ””โ”€โ”€ square.js
โ”‚   โ”œโ”€โ”€ index.css
โ”‚   โ”œโ”€โ”€ index.js
โ”‚   โ”œโ”€โ”€ logo.svg
โ”‚   โ””โ”€โ”€ utils/
โ”‚       โ””โ”€โ”€ index.js
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ yarn.lock

8 directories, 19 files

yarn eject/npm run eject

WARNING: EJECTING IS PERMANENT. There is no 'rewind' feature.

If the needs of your application extend outside of the configuration and options provided by Create-React-App, you can eject out of Create-React-App by called yarn eject/npm run eject. Calling this command will remove the abstractions and niceties provided by Create-React-App. The configuration files, application dependencies, and NPM scripts will be exposed and available to modify as needed.

Post-Eject Directory Structure:

 # Configuration files for Jest & Webpack, and polyfills for Promises and Object.assign()
 โ”œโ”€โ”€ config/
 โ”‚   โ”œโ”€โ”€ env.js
 โ”‚   โ”œโ”€โ”€ jest/
 โ”‚   โ”‚   โ”œโ”€โ”€ cssTransform.js
 โ”‚   โ”‚   โ””โ”€โ”€ fileTransform.js
 โ”‚   โ”œโ”€โ”€ paths.js
 โ”‚   โ”œโ”€โ”€ polyfills.js
 โ”‚   โ”œโ”€โ”€ webpack.config.dev.js
 โ”‚   โ””โ”€โ”€ webpack.config.prod.js
 โ”œโ”€โ”€ node_modules/     # Installed packages necessary for Create-React-App
 โ”œโ”€โ”€ package.json
 โ”œโ”€โ”€ public/
 โ”‚   โ”œโ”€โ”€ favicon.ico
 โ”‚   โ””โ”€โ”€ index.html
 โ”œโ”€โ”€ scripts/          # Exposed React Scripts
 โ”‚   โ”œโ”€โ”€ build.js
 โ”‚   โ”œโ”€โ”€ start.js
 โ”‚   โ””โ”€โ”€ test.js
 โ”œโ”€โ”€ src/
 โ”‚   โ”œโ”€โ”€ components/
 โ”‚   โ”‚   โ”œโ”€โ”€ board.js
 โ”‚   โ”‚   โ”œโ”€โ”€ game.js
 โ”‚   โ”‚   โ””โ”€โ”€ square.js
 โ”‚   โ”œโ”€โ”€ index.css
 โ”‚   โ”œโ”€โ”€ index.js
 โ”‚   โ”œโ”€โ”€ logo.svg
 โ”‚   โ””โ”€โ”€ utils/
 โ”‚       โ””โ”€โ”€ index.js
 โ””โ”€โ”€ yarn.lock

8 directories, 21 files
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].