Create React App Documentation

repository·main·Indexed 33 days ago

https://github.com/react/create-react-app

A tool for bootstrapping React applications with no manual build configuration. Includes preconfigured environments with Webpack, Babel, and ESLint. Documentation covers project bootstrapping, TypeScript templates, babel-preset-react-app configuration, eslint-config-react-app usage, and polyfilling for older browsers.

Tokens
37.6K
Snippets
168
Records
259
Agent score
100%

What's inside create-react-app

  1. New features in Create React App 4.0.x

    main

    Version 4.0.x introduced several enhancements to the development experience:

    • Image Support: Added AVIF image support in react-scripts.
    • Testing:
      • Added testMatch support for Jest configuration.
      • Added Jest and testing-library rules to eslint-config-react-app.
      • Added support for .cjs and .mjs files in the test runner.
    • Build & Performance:
      • Re-introduced --stats output from Webpack.
      • Added performance relayer and documentation (web-vitals) to templates.
    • Developer Experience:
      • Added experimental react-refresh support.
      • Added a Fast Refresh warning when using React versions older than 16.10.
  2. What is included in a Create React App project?

    main

    Create React App provides a preconfigured environment for building modern single-page React applications without manual configuration of tools like Webpack or Babel.

    Key features included:

    • Syntax Support: React, JSX, ES6, TypeScript, and Flow.
    • CSS: Autoprefixed CSS support.
    • Testing: A fast interactive unit test runner with coverage reporting.
    • Development Server: A live server that warns about common mistakes.
    • Production Build: A script to bundle JS, CSS, and images with hashes and sourcemaps.
    • PWA Support: An offline-first service worker and web app manifest (service worker usage is opt-in).

    Philosophy:

    • One Dependency: Uses a curated set of tools (Webpack, Babel, ESLint) under a single dependency.
    • No Configuration Required: Reasonable defaults for development and production are handled for you.
    • No Lock-In: You can "eject" at any time to move all configuration and build dependencies directly into your project for custom management.
  3. Understand the difference between create-react-app and react-scripts

    main

    Create React App is split into two distinct parts that serve different purposes:

    1. create-react-app: A global command-line utility used solely to scaffold and create new projects.
    2. react-scripts: A development dependency installed inside your project. It contains the actual build tools, scripts, and configurations used to run, test, and build your application.

    When you create a new app, it automatically uses the latest version of react-scripts.

  4. Use the public folder and %PUBLIC_URL% variable

    main

    In version 0.5.0 and later, the public folder is used for static assets. To reference these assets within public/index.html, use the %PUBLIC_URL% placeholder. This placeholder is replaced during the build process to ensure paths are correct regardless of your deployment sub-directory or client-side routing configuration.

    Example usage in index.html:

    <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
  5. Supported JavaScript language features

    main

    Create React App supports a superset of the latest JavaScript standard. In addition to ES6, the following features are supported:

    • Exponentiation Operator (ES2016)
    • Async/await (ES2017)
    • Object Rest/Spread Properties (ES2018)
    • Dynamic import() (stage 4 proposal)
    • Class Fields and Static Properties (stage 3 proposal)
    • JSX, Flow, and TypeScript

    If you use ES6+ features that require runtime support (such as Array.from() or Symbol), you must include the appropriate polyfills manually or ensure your target browsers already support them.

  6. Set baseUrl from jsconfig.json or tsconfig.json

    main
    In react-scripts (version 3.4.0 and later), the baseUrl configuration can be automatically set from your jsconfig.json or tsconfig.json files. This allows for cleaner absolute imports based on your project's configuration.