├── .editorconfig
├── .gitignore
├── .rollup.js
├── .travis.yml
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE.md
├── README.md
├── index.js
├── package.json
├── test-cra1
├── .gitignore
├── README.md
├── config-overrides.js
├── package.json
├── public
│ ├── favicon.ico
│ ├── index.html
│ └── manifest.json
└── src
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── index.css
│ ├── index.js
│ ├── logo.svg
│ └── serviceWorker.js
└── test-cra2
├── .gitignore
├── README.md
├── config-overrides.js
├── package.json
├── postcss.config.js
├── public
├── favicon.ico
├── index.html
└── manifest.json
└── src
├── App.css
├── App.js
├── App.test.js
├── index.css
├── index.js
├── logo.svg
└── serviceWorker.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | end_of_line = lf
6 | indent_style = tab
7 | insert_final_newline = true
8 | trim_trailing_whitespace = true
9 |
10 | [*.md]
11 | trim_trailing_whitespace = false
12 |
13 | [*.{json,md,yml}]
14 | indent_size = 2
15 | indent_style = space
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | index.*.*
3 | package-lock.json
4 | *.log*
5 | .*
6 | !.editorconfig
7 | !.gitignore
8 | !.rollup.js
9 | !.travis.yml
10 |
--------------------------------------------------------------------------------
/.rollup.js:
--------------------------------------------------------------------------------
1 | import babel from 'rollup-plugin-babel';
2 |
3 | export default {
4 | input: 'index.js',
5 | output: [
6 | { file: 'index.cjs.js', format: 'cjs', sourcemap: true },
7 | { file: 'index.es.mjs', format: 'es', sourcemap: true }
8 | ],
9 | plugins: [
10 | babel({
11 | presets: [
12 | ['@babel/env', { modules: false, targets: { node: 8 } }]
13 | ]
14 | })
15 | ]
16 | };
17 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # https://docs.travis-ci.com/user/travis-lint
2 |
3 | language: node_js
4 |
5 | node_js:
6 | - 8
7 |
8 | install:
9 | - npm install --ignore-scripts
10 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changes to React App Rewire PostCSS
2 |
3 | ### 4.0.0 (May 12, 2019)
4 |
5 | - Updated: Node 8+ compatibility (major)
6 |
7 | ### 3.0.2 (October 13, 2018)
8 |
9 | - Fixed: Issue with loading from postcss.config.js file
10 |
11 | ### 3.0.1 (October 9, 2018)
12 |
13 | - Fixed: Issue with `build`
14 |
15 | ### 3.0.0 (October 3, 2018)
16 |
17 | - Updated: Support for Create React App 2.
18 | - Changed: The old PostCSS plugins are no longer erased, making
19 | configuration-less usage of this plugin seemingly invisible. The plugins are
20 | still replaced the same way.
21 |
22 | ### 2.0.0 (September 17, 2018)
23 |
24 | - Changed: A new configuration is returned, instead of the existing
25 | configuration being mutated.
26 | - Updated: PostCSS Loader v3.0.0 (major)
27 | - Updated: Support for Node v6+ (major)
28 |
29 | ### 1.0.2 (June 5, 2018)
30 |
31 | - Fixed: Issue detecting postcss-loader in Windows
32 |
33 | ### 1.0.1 (June 5, 2018)
34 |
35 | - Improved documentation
36 | - Moved project to csstools
37 |
38 | ### 1.0.0 (June 5, 2018)
39 |
40 | - Initial version
41 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to React App Rewire PostCSS
2 |
3 | You want to help? You rock! Now, take a moment to be sure your contributions
4 | make sense to everyone else.
5 |
6 | ## Reporting Issues
7 |
8 | Found a problem? Want a new feature?
9 |
10 | - See if your issue or idea has [already been reported].
11 | - Provide a [reduced test case] or a [live example].
12 |
13 | Remember, a bug is a _demonstrable problem_ caused by _our_ code.
14 |
15 | ## Submitting Pull Requests
16 |
17 | Pull requests are the greatest contributions, so be sure they are focused in
18 | scope and avoid unrelated commits.
19 |
20 | 1. To begin; [fork this project], clone your fork, and add our upstream.
21 | ```bash
22 | # Clone your fork of the repo into the current directory
23 | git clone git@github.com:YOUR_USER/react-app-rewire-postcss.git
24 |
25 | # Navigate to the newly cloned directory
26 | cd react-app-rewire-postcss
27 |
28 | # Assign the original repo to a remote called "upstream"
29 | git remote add upstream git@github.com:csstools/react-app-rewire-postcss.git
30 |
31 | # Install the tools necessary for testing
32 | npm install
33 | ```
34 |
35 | 2. Create a branch for your feature or fix:
36 | ```bash
37 | # Move into a new branch for your feature
38 | git checkout -b feature/thing
39 | ```
40 | ```bash
41 | # Move into a new branch for your fix
42 | git checkout -b fix/something
43 | ```
44 |
45 | 3. If your code follows our practices, then push your feature branch:
46 | ```bash
47 | # Test current code
48 | npm test
49 | ```
50 | ```bash
51 | # Push the branch for your new feature
52 | git push origin feature/thing
53 | ```
54 | ```bash
55 | # Or, push the branch for your update
56 | git push origin update/something
57 | ```
58 |
59 | That’s it! Now [open a pull request] with a clear title and description.
60 |
61 | [already been reported]: issues
62 | [fork this project]: fork
63 | [live example]: https://codepen.io/pen
64 | [open a pull request]: https://help.github.com/articles/using-pull-requests/
65 | [reduced test case]: https://css-tricks.com/reduced-test-cases/
66 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # CC0 1.0 Universal
2 |
3 | ## Statement of Purpose
4 |
5 | The laws of most jurisdictions throughout the world automatically confer
6 | exclusive Copyright and Related Rights (defined below) upon the creator and
7 | subsequent owner(s) (each and all, an “owner”) of an original work of
8 | authorship and/or a database (each, a “Work”).
9 |
10 | Certain owners wish to permanently relinquish those rights to a Work for the
11 | purpose of contributing to a commons of creative, cultural and scientific works
12 | (“Commons”) that the public can reliably and without fear of later claims of
13 | infringement build upon, modify, incorporate in other works, reuse and
14 | redistribute as freely as possible in any form whatsoever and for any purposes,
15 | including without limitation commercial purposes. These owners may contribute
16 | to the Commons to promote the ideal of a free culture and the further
17 | production of creative, cultural and scientific works, or to gain reputation or
18 | greater distribution for their Work in part through the use and efforts of
19 | others.
20 |
21 | For these and/or other purposes and motivations, and without any expectation of
22 | additional consideration or compensation, the person associating CC0 with a
23 | Work (the “Affirmer”), to the extent that he or she is an owner of Copyright
24 | and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and
25 | publicly distribute the Work under its terms, with knowledge of his or her
26 | Copyright and Related Rights in the Work and the meaning and intended legal
27 | effect of CC0 on those rights.
28 |
29 | 1. Copyright and Related Rights. A Work made available under CC0 may be
30 | protected by copyright and related or neighboring rights (“Copyright and
31 | Related Rights”). Copyright and Related Rights include, but are not limited
32 | to, the following:
33 | 1. the right to reproduce, adapt, distribute, perform, display, communicate,
34 | and translate a Work;
35 | 2. moral rights retained by the original author(s) and/or performer(s);
36 | 3. publicity and privacy rights pertaining to a person’s image or likeness
37 | depicted in a Work;
38 | 4. rights protecting against unfair competition in regards to a Work,
39 | subject to the limitations in paragraph 4(i), below;
40 | 5. rights protecting the extraction, dissemination, use and reuse of data in
41 | a Work;
42 | 6. database rights (such as those arising under Directive 96/9/EC of the
43 | European Parliament and of the Council of 11 March 1996 on the legal
44 | protection of databases, and under any national implementation thereof,
45 | including any amended or successor version of such directive); and
46 | 7. other similar, equivalent or corresponding rights throughout the world
47 | based on applicable law or treaty, and any national implementations
48 | thereof.
49 |
50 | 2. Waiver. To the greatest extent permitted by, but not in contravention of,
51 | applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
52 | unconditionally waives, abandons, and surrenders all of Affirmer’s Copyright
53 | and Related Rights and associated claims and causes of action, whether now
54 | known or unknown (including existing as well as future claims and causes of
55 | action), in the Work (i) in all territories worldwide, (ii) for the maximum
56 | duration provided by applicable law or treaty (including future time
57 | extensions), (iii) in any current or future medium and for any number of
58 | copies, and (iv) for any purpose whatsoever, including without limitation
59 | commercial, advertising or promotional purposes (the “Waiver”). Affirmer
60 | makes the Waiver for the benefit of each member of the public at large and
61 | to the detriment of Affirmer’s heirs and successors, fully intending that
62 | such Waiver shall not be subject to revocation, rescission, cancellation,
63 | termination, or any other legal or equitable action to disrupt the quiet
64 | enjoyment of the Work by the public as contemplated by Affirmer’s express
65 | Statement of Purpose.
66 |
67 | 3. Public License Fallback. Should any part of the Waiver for any reason be
68 | judged legally invalid or ineffective under applicable law, then the Waiver
69 | shall be preserved to the maximum extent permitted taking into account
70 | Affirmer’s express Statement of Purpose. In addition, to the extent the
71 | Waiver is so judged Affirmer hereby grants to each affected person a
72 | royalty-free, non transferable, non sublicensable, non exclusive,
73 | irrevocable and unconditional license to exercise Affirmer’s Copyright and
74 | Related Rights in the Work (i) in all territories worldwide, (ii) for the
75 | maximum duration provided by applicable law or treaty (including future time
76 | extensions), (iii) in any current or future medium and for any number of
77 | copies, and (iv) for any purpose whatsoever, including without limitation
78 | commercial, advertising or promotional purposes (the “License”). The License
79 | shall be deemed effective as of the date CC0 was applied by Affirmer to the
80 | Work. Should any part of the License for any reason be judged legally
81 | invalid or ineffective under applicable law, such partial invalidity or
82 | ineffectiveness shall not invalidate the remainder of the License, and in
83 | such case Affirmer hereby affirms that he or she will not (i) exercise any
84 | of his or her remaining Copyright and Related Rights in the Work or (ii)
85 | assert any associated claims and causes of action with respect to the Work,
86 | in either case contrary to Affirmer’s express Statement of Purpose.
87 |
88 | 4. Limitations and Disclaimers.
89 | 1. No trademark or patent rights held by Affirmer are waived, abandoned,
90 | surrendered, licensed or otherwise affected by this document.
91 | 2. Affirmer offers the Work as-is and makes no representations or warranties
92 | of any kind concerning the Work, express, implied, statutory or
93 | otherwise, including without limitation warranties of title,
94 | merchantability, fitness for a particular purpose, non infringement, or
95 | the absence of latent or other defects, accuracy, or the present or
96 | absence of errors, whether or not discoverable, all to the greatest
97 | extent permissible under applicable law.
98 | 3. Affirmer disclaims responsibility for clearing rights of other persons
99 | that may apply to the Work or any use thereof, including without
100 | limitation any person’s Copyright and Related Rights in the Work.
101 | Further, Affirmer disclaims responsibility for obtaining any necessary
102 | consents, permissions or other rights required for any use of the Work.
103 | 4. Affirmer understands and acknowledges that Creative Commons is not a
104 | party to this document and has no duty or obligation with respect to this
105 | CC0 or use of the Work.
106 |
107 | For more information, please see
108 | http://creativecommons.org/publicdomain/zero/1.0/.
109 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
⚠️ React App Rewire PostCSS has been deprecated. ⚠️
2 |
3 | # React App Rewire PostCSS [][postcss]
4 |
5 | [![NPM Version][npm-img]][npm-url]
6 | [![Build Status][cli-img]][cli-url]
7 | [![Support Chat][git-img]][git-url]
8 |
9 | [React App Rewire PostCSS] lets you configure [PostCSS] in [Create React App]
10 | v1 and v2 without ejecting.
11 |
12 | ## Usage
13 |
14 | Add [React App Rewire PostCSS] to your [Rewired] React app:
15 |
16 | ```bash
17 | npm install react-app-rewire-postcss --save-dev
18 | ```
19 |
20 | Next, add [React App Rewire PostCSS] to `config-overrides.js` in your React app
21 | directory:
22 |
23 | ```js
24 | module.exports = config => {
25 | require('react-app-rewire-postcss')(config/*, options */);
26 |
27 | return config;
28 | };
29 | ```
30 |
31 | That’s it! Now you can control PostCSS with all the configuration options from
32 | [PostCSS Loader]:
33 |
34 | ```js
35 | module.exports = config => {
36 | require('react-app-rewire-postcss')(config, {
37 | plugins: loader => [
38 | require('postcss-preset-env')()
39 | ]
40 | });
41 |
42 | return config;
43 | };
44 | ```
45 |
46 | Alternatively, you can now use `postcss.config.js` in your React app directory:
47 |
48 | ```js
49 | module.exports = config => {
50 | require('react-app-rewire-postcss')(config, true /* any truthy value will do */);
51 |
52 | return config;
53 | };
54 | ```
55 |
56 | ```js
57 | module.exports = {
58 | plugins: {
59 | 'postcss-preset-env': {
60 | stage: 0
61 | }
62 | }
63 | };
64 | ```
65 |
66 | And you can leverage [Browserslist] by adding a `.browserslistrc` to your React
67 | app directory:
68 |
69 |
70 |
71 | ```yaml
72 | # browsers we support
73 |
74 | > 2%
75 | not dead
76 | ```
77 |
78 | ---
79 |
80 | Happy PostCSS’ing!
81 |
82 | [cli-img]: https://img.shields.io/travis/csstools/react-app-rewire-postcss.svg
83 | [cli-url]: https://travis-ci.org/csstools/react-app-rewire-postcss
84 | [git-img]: https://img.shields.io/badge/support-chat-blue.svg
85 | [git-url]: https://gitter.im/postcss/postcss
86 | [npm-img]: https://img.shields.io/npm/v/react-app-rewire-postcss.svg
87 | [npm-url]: https://www.npmjs.com/package/react-app-rewire-postcss
88 |
89 | [Browserslist]: https://github.com/browserslist/browserslist
90 | [Create React App]: https://github.com/facebook/create-react-app
91 | [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
92 | [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
93 | [PostCSS]: https://github.com/postcss/postcss
94 | [PostCSS Loader]: https://github.com/postcss/postcss-loader
95 | [React App Rewire PostCSS]: https://github.com/csstools/react-app-rewire-postcss
96 | [React App Rewired]: https://github.com/timarney/react-app-rewired
97 | [rewired]: https://github.com/timarney/react-app-rewired#how-to-rewire-your-create-react-app-project
98 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | export default (config, options) => {
2 | // find any first matching rule that contains postcss-loader
3 | filterPostCSSLoader(config.module.rules).forEach(rule => {
4 | filterPostCSSLoader(rule.oneOf).forEach(oneOf => {
5 | filterPostCSSLoader(oneOf.use || oneOf.loader).forEach(use => {
6 | // use the latest version of postcss-loader
7 | use.loader = require.resolve('postcss-loader');
8 |
9 | // conditionally replace options with a custom configuration
10 | use.options = options
11 | ? Object.assign({ ident: 'postcss' }, options)
12 | : Object.assign(use.options, options)
13 | })
14 | })
15 | });
16 |
17 | // return the mutated configuration
18 | return config;
19 | };
20 |
21 | // return a filtered array that includes postcss-loader
22 | const filterPostCSSLoader = array => array.filter(object => JSON.stringify(object).includes('postcss-loader'));
23 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-app-rewire-postcss",
3 | "version": "4.0.0",
4 | "description": "Configure PostCSS in Create React App without ejecting",
5 | "author": "Jonathan Neal ",
6 | "license": "CC0-1.0",
7 | "repository": "csstools/react-app-rewire-postcss",
8 | "homepage": "https://github.com/csstools/react-app-rewire-postcss#readme",
9 | "bugs": "https://github.com/csstools/react-app-rewire-postcss/issues",
10 | "main": "index.cjs.js",
11 | "module": "index.es.mjs",
12 | "files": [
13 | "index.cjs.js",
14 | "index.cjs.js.map",
15 | "index.es.mjs",
16 | "index.es.mjs.map"
17 | ],
18 | "scripts": {
19 | "prepublishOnly": "npm test",
20 | "pretest": "rollup -c .rollup.js --silent",
21 | "test": "echo 'Running tests...'; npm run test:js",
22 | "test:js": "eslint *.js --cache --ignore-path .gitignore --quiet"
23 | },
24 | "engines": {
25 | "node": ">=8.0.0"
26 | },
27 | "dependencies": {
28 | "postcss-loader": "^3.0.0"
29 | },
30 | "devDependencies": {
31 | "@babel/core": "7.4.4",
32 | "@babel/preset-env": "7.4.4",
33 | "babel-eslint": "10.0.1",
34 | "eslint": "5.16.0",
35 | "eslint-config-dev": "2.0.0",
36 | "pre-commit": "1.2.2",
37 | "rollup": "1.11.3",
38 | "rollup-plugin-babel": "4.3.2"
39 | },
40 | "eslintConfig": {
41 | "extends": "dev",
42 | "parser": "babel-eslint"
43 | },
44 | "keywords": [
45 | "react",
46 | "create-react-app",
47 | "react-app-rewire",
48 | "rewire",
49 | "postcss",
50 | "postcss-loader",
51 | "postcss-plugin",
52 | "css"
53 | ]
54 | }
55 |
--------------------------------------------------------------------------------
/test-cra1/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 |
6 | # testing
7 | /coverage
8 |
9 | # production
10 | /build
11 |
12 | # misc
13 | .DS_Store
14 | .env.local
15 | .env.development.local
16 | .env.test.local
17 | .env.production.local
18 |
19 | npm-debug.log*
20 | yarn-debug.log*
21 | yarn-error.log*
22 |
--------------------------------------------------------------------------------
/test-cra1/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2 |
3 | Below you will find some information on how to perform common tasks.
4 | You can find the most recent version of this guide [here](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md).
5 |
6 | ## Table of Contents
7 |
8 | - [Updating to New Releases](#updating-to-new-releases)
9 | - [Sending Feedback](#sending-feedback)
10 | - [Folder Structure](#folder-structure)
11 | - [Available Scripts](#available-scripts)
12 | - [npm start](#npm-start)
13 | - [npm test](#npm-test)
14 | - [npm run build](#npm-run-build)
15 | - [npm run eject](#npm-run-eject)
16 | - [Supported Browsers](#supported-browsers)
17 | - [Supported Language Features](#supported-language-features)
18 | - [Syntax Highlighting in the Editor](#syntax-highlighting-in-the-editor)
19 | - [Displaying Lint Output in the Editor](#displaying-lint-output-in-the-editor)
20 | - [Debugging in the Editor](#debugging-in-the-editor)
21 | - [Formatting Code Automatically](#formatting-code-automatically)
22 | - [Changing the Page ``](#changing-the-page-title)
23 | - [Installing a Dependency](#installing-a-dependency)
24 | - [Importing a Component](#importing-a-component)
25 | - [Code Splitting](#code-splitting)
26 | - [Adding a Stylesheet](#adding-a-stylesheet)
27 | - [Adding a CSS Modules Stylesheet](#adding-a-css-modules-stylesheet)
28 | - [Adding a Sass Stylesheet](#adding-a-sass-stylesheet)
29 | - [Post-Processing CSS](#post-processing-css)
30 | - [Adding Images, Fonts, and Files](#adding-images-fonts-and-files)
31 | - [Adding SVGs](#adding-svgs)
32 | - [Using the `public` Folder](#using-the-public-folder)
33 | - [Changing the HTML](#changing-the-html)
34 | - [Adding Assets Outside of the Module System](#adding-assets-outside-of-the-module-system)
35 | - [When to Use the `public` Folder](#when-to-use-the-public-folder)
36 | - [Using Global Variables](#using-global-variables)
37 | - [Adding Bootstrap](#adding-bootstrap)
38 | - [Using a Custom Theme](#using-a-custom-theme)
39 | - [Adding Flow](#adding-flow)
40 | - [Adding a Router](#adding-a-router)
41 | - [Adding Custom Environment Variables](#adding-custom-environment-variables)
42 | - [Referencing Environment Variables in the HTML](#referencing-environment-variables-in-the-html)
43 | - [Adding Temporary Environment Variables In Your Shell](#adding-temporary-environment-variables-in-your-shell)
44 | - [Adding Development Environment Variables In `.env`](#adding-development-environment-variables-in-env)
45 | - [Can I Use Decorators?](#can-i-use-decorators)
46 | - [Fetching Data with AJAX Requests](#fetching-data-with-ajax-requests)
47 | - [Integrating with an API Backend](#integrating-with-an-api-backend)
48 | - [Node](#node)
49 | - [Ruby on Rails](#ruby-on-rails)
50 | - [Proxying API Requests in Development](#proxying-api-requests-in-development)
51 | - ["Invalid Host Header" Errors After Configuring Proxy](#invalid-host-header-errors-after-configuring-proxy)
52 | - [Configuring the Proxy Manually](#configuring-the-proxy-manually)
53 | - [Using HTTPS in Development](#using-https-in-development)
54 | - [Generating Dynamic `` Tags on the Server](#generating-dynamic-meta-tags-on-the-server)
55 | - [Pre-Rendering into Static HTML Files](#pre-rendering-into-static-html-files)
56 | - [Injecting Data from the Server into the Page](#injecting-data-from-the-server-into-the-page)
57 | - [Running Tests](#running-tests)
58 | - [Filename Conventions](#filename-conventions)
59 | - [Command Line Interface](#command-line-interface)
60 | - [Version Control Integration](#version-control-integration)
61 | - [Writing Tests](#writing-tests)
62 | - [Testing Components](#testing-components)
63 | - [Using Third Party Assertion Libraries](#using-third-party-assertion-libraries)
64 | - [Initializing Test Environment](#initializing-test-environment)
65 | - [Focusing and Excluding Tests](#focusing-and-excluding-tests)
66 | - [Coverage Reporting](#coverage-reporting)
67 | - [Continuous Integration](#continuous-integration)
68 | - [Disabling jsdom](#disabling-jsdom)
69 | - [Snapshot Testing](#snapshot-testing)
70 | - [Editor Integration](#editor-integration)
71 | - [Debugging Tests](#debugging-tests)
72 | - [Debugging Tests in Chrome](#debugging-tests-in-chrome)
73 | - [Debugging Tests in Visual Studio Code](#debugging-tests-in-visual-studio-code)
74 | - [Developing Components in Isolation](#developing-components-in-isolation)
75 | - [Getting Started with Storybook](#getting-started-with-storybook)
76 | - [Getting Started with Styleguidist](#getting-started-with-styleguidist)
77 | - [Publishing Components to npm](#publishing-components-to-npm)
78 | - [Making a Progressive Web App](#making-a-progressive-web-app)
79 | - [Why Opt-in?](#why-opt-in)
80 | - [Offline-First Considerations](#offline-first-considerations)
81 | - [Progressive Web App Metadata](#progressive-web-app-metadata)
82 | - [Analyzing the Bundle Size](#analyzing-the-bundle-size)
83 | - [Deployment](#deployment)
84 | - [Static Server](#static-server)
85 | - [Other Solutions](#other-solutions)
86 | - [Serving Apps with Client-Side Routing](#serving-apps-with-client-side-routing)
87 | - [Building for Relative Paths](#building-for-relative-paths)
88 | - [Customizing Environment Variables for Arbitrary Build Environments](#customizing-environment-variables-for-arbitrary-build-environments)
89 | - [Azure](#azure)
90 | - [Firebase](#firebase)
91 | - [GitHub Pages](#github-pages)
92 | - [Heroku](#heroku)
93 | - [Netlify](#netlify)
94 | - [Now](#now)
95 | - [S3 and CloudFront](#s3-and-cloudfront)
96 | - [Surge](#surge)
97 | - [Advanced Configuration](#advanced-configuration)
98 | - [Troubleshooting](#troubleshooting)
99 | - [`npm start` doesn’t detect changes](#npm-start-doesnt-detect-changes)
100 | - [`npm test` hangs or crashes on macOS Sierra](#npm-test-hangs-or-crashes-on-macos-sierra)
101 | - [`npm run build` exits too early](#npm-run-build-exits-too-early)
102 | - [`npm run build` fails on Heroku](#npm-run-build-fails-on-heroku)
103 | - [`npm run build` fails to minify](#npm-run-build-fails-to-minify)
104 | - [Moment.js locales are missing](#momentjs-locales-are-missing)
105 | - [Alternatives to Ejecting](#alternatives-to-ejecting)
106 | - [Something Missing?](#something-missing)
107 |
108 | ## Updating to New Releases
109 |
110 | Create React App is divided into two packages:
111 |
112 | - `create-react-app` is a global command-line utility that you use to create new projects.
113 | - `react-scripts` is a development dependency in the generated projects (including this one).
114 |
115 | You almost never need to update `create-react-app` itself: it delegates all the setup to `react-scripts`.
116 |
117 | When you run `create-react-app`, it always creates the project with the latest version of `react-scripts` so you’ll get all the new features and improvements in newly created apps automatically.
118 |
119 | To update an existing project to a new version of `react-scripts`, [open the changelog](https://github.com/facebook/create-react-app/blob/master/CHANGELOG.md), find the version you’re currently on (check `package.json` in this folder if you’re not sure), and apply the migration instructions for the newer versions.
120 |
121 | In most cases bumping the `react-scripts` version in `package.json` and running `npm install` (or `yarn install`) in this folder should be enough, but it’s good to consult the [changelog](https://github.com/facebook/create-react-app/blob/master/CHANGELOG.md) for potential breaking changes.
122 |
123 | We commit to keeping the breaking changes minimal so you can upgrade `react-scripts` painlessly.
124 |
125 | ## Sending Feedback
126 |
127 | We are always open to [your feedback](https://github.com/facebook/create-react-app/issues).
128 |
129 | ## Folder Structure
130 |
131 | After creation, your project should look like this:
132 |
133 | ```
134 | my-app/
135 | README.md
136 | node_modules/
137 | package.json
138 | public/
139 | index.html
140 | favicon.ico
141 | src/
142 | App.css
143 | App.js
144 | App.test.js
145 | index.css
146 | index.js
147 | logo.svg
148 | ```
149 |
150 | For the project to build, **these files must exist with exact filenames**:
151 |
152 | - `public/index.html` is the page template;
153 | - `src/index.js` is the JavaScript entry point.
154 |
155 | You can delete or rename the other files.
156 |
157 | You may create subdirectories inside `src`. For faster rebuilds, only files inside `src` are processed by Webpack.
158 | You need to **put any JS and CSS files inside `src`**, otherwise Webpack won’t see them.
159 |
160 | Only files inside `public` can be used from `public/index.html`.
161 | Read instructions below for using assets from JavaScript and HTML.
162 |
163 | You can, however, create more top-level directories.
164 | They will not be included in the production build so you can use them for things like documentation.
165 |
166 | ## Available Scripts
167 |
168 | In the project directory, you can run:
169 |
170 | ### `npm start`
171 |
172 | Runs the app in the development mode.
173 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
174 |
175 | The page will reload if you make edits.
176 | You will also see any lint errors in the console.
177 |
178 | ### `npm test`
179 |
180 | Launches the test runner in the interactive watch mode.
181 | See the section about [running tests](#running-tests) for more information.
182 |
183 | ### `npm run build`
184 |
185 | Builds the app for production to the `build` folder.
186 | It correctly bundles React in production mode and optimizes the build for the best performance.
187 |
188 | The build is minified and the filenames include the hashes.
189 | Your app is ready to be deployed!
190 |
191 | See the section about [deployment](#deployment) for more information.
192 |
193 | ### `npm run eject`
194 |
195 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
196 |
197 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
198 |
199 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
200 |
201 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
202 |
203 | ## Supported Browsers
204 |
205 | By default, the generated project supports all modern browsers.
206 | Support for Internet Explorer 9, 10, and 11 requires [polyfills](https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md).
207 |
208 | ### Supported Language Features
209 |
210 | This project supports a superset of the latest JavaScript standard.
211 | In addition to [ES6](https://github.com/lukehoban/es6features) syntax features, it also supports:
212 |
213 | - [Exponentiation Operator](https://github.com/rwaldron/exponentiation-operator) (ES2016).
214 | - [Async/await](https://github.com/tc39/ecmascript-asyncawait) (ES2017).
215 | - [Object Rest/Spread Properties](https://github.com/tc39/proposal-object-rest-spread) (ES2018).
216 | - [Dynamic import()](https://github.com/tc39/proposal-dynamic-import) (stage 3 proposal)
217 | - [Class Fields and Static Properties](https://github.com/tc39/proposal-class-public-fields) (part of stage 3 proposal).
218 | - [JSX](https://facebook.github.io/react/docs/introducing-jsx.html) and [Flow](https://flow.org/) syntax.
219 |
220 | Learn more about [different proposal stages](https://babeljs.io/docs/plugins/#presets-stage-x-experimental-presets-).
221 |
222 | While we recommend using experimental proposals with some caution, Facebook heavily uses these features in the product code, so we intend to provide [codemods](https://medium.com/@cpojer/effective-javascript-codemods-5a6686bb46fb) if any of these proposals change in the future.
223 |
224 | Note that **this project includes no [polyfills](https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md)** by default.
225 |
226 | If you use any other ES6+ features that need **runtime support** (such as `Array.from()` or `Symbol`), make sure you are [including the appropriate polyfills manually](https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md), or that the browsers you are targeting already support them.
227 |
228 | ## Syntax Highlighting in the Editor
229 |
230 | To configure the syntax highlighting in your favorite text editor, head to the [relevant Babel documentation page](https://babeljs.io/docs/editors) and follow the instructions. Some of the most popular editors are covered.
231 |
232 | ## Displaying Lint Output in the Editor
233 |
234 | > Note: this feature is available with `react-scripts@0.2.0` and higher.
235 | > It also only works with npm 3 or higher.
236 |
237 | Some editors, including Sublime Text, Atom, and Visual Studio Code, provide plugins for ESLint.
238 |
239 | They are not required for linting. You should see the linter output right in your terminal as well as the browser console. However, if you prefer the lint results to appear right in your editor, there are some extra steps you can do.
240 |
241 | You would need to install an ESLint plugin for your editor first. Then, add a file called `.eslintrc` to the project root:
242 |
243 | ```js
244 | {
245 | "extends": "react-app"
246 | }
247 | ```
248 |
249 | Now your editor should report the linting warnings.
250 |
251 | Note that even if you edit your `.eslintrc` file further, these changes will **only affect the editor integration**. They won’t affect the terminal and in-browser lint output. This is because Create React App intentionally provides a minimal set of rules that find common mistakes.
252 |
253 | If you want to enforce a coding style for your project, consider using [Prettier](https://github.com/jlongster/prettier) instead of ESLint style rules.
254 |
255 | ## Debugging in the Editor
256 |
257 | **This feature is currently only supported by [Visual Studio Code](https://code.visualstudio.com) and [WebStorm](https://www.jetbrains.com/webstorm/).**
258 |
259 | Visual Studio Code and WebStorm support debugging out of the box with Create React App. This enables you as a developer to write and debug your React code without leaving the editor, and most importantly it enables you to have a continuous development workflow, where context switching is minimal, as you don’t have to switch between tools.
260 |
261 | ### Visual Studio Code
262 |
263 | You would need to have the latest version of [VS Code](https://code.visualstudio.com) and VS Code [Chrome Debugger Extension](https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome) installed.
264 |
265 | Then add the block below to your `launch.json` file and put it inside the `.vscode` folder in your app’s root directory.
266 |
267 | ```json
268 | {
269 | "version": "0.2.0",
270 | "configurations": [
271 | {
272 | "name": "Chrome",
273 | "type": "chrome",
274 | "request": "launch",
275 | "url": "http://localhost:3000",
276 | "webRoot": "${workspaceRoot}/src",
277 | "sourceMapPathOverrides": {
278 | "webpack:///src/*": "${webRoot}/*"
279 | }
280 | }
281 | ]
282 | }
283 | ```
284 |
285 | > Note: the URL may be different if you've made adjustments via the [HOST or PORT environment variables](#advanced-configuration).
286 |
287 | Start your app by running `npm start`, and start debugging in VS Code by pressing `F5` or by clicking the green debug icon. You can now write code, set breakpoints, make changes to the code, and debug your newly modified code—all from your editor.
288 |
289 | Having problems with VS Code Debugging? Please see their [troubleshooting guide](https://github.com/Microsoft/vscode-chrome-debug/blob/master/README.md#troubleshooting).
290 |
291 | ### WebStorm
292 |
293 | You would need to have [WebStorm](https://www.jetbrains.com/webstorm/) and [JetBrains IDE Support](https://chrome.google.com/webstore/detail/jetbrains-ide-support/hmhgeddbohgjknpmjagkdomcpobmllji) Chrome extension installed.
294 |
295 | In the WebStorm menu `Run` select `Edit Configurations...`. Then click `+` and select `JavaScript Debug`. Paste `http://localhost:3000` into the URL field and save the configuration.
296 |
297 | > Note: the URL may be different if you've made adjustments via the [HOST or PORT environment variables](#advanced-configuration).
298 |
299 | Start your app by running `npm start`, then press `^D` on macOS or `F9` on Windows and Linux or click the green debug icon to start debugging in WebStorm.
300 |
301 | The same way you can debug your application in IntelliJ IDEA Ultimate, PhpStorm, PyCharm Pro, and RubyMine.
302 |
303 | ## Formatting Code Automatically
304 |
305 | Prettier is an opinionated code formatter with support for JavaScript, CSS and JSON. With Prettier you can format the code you write automatically to ensure a code style within your project. See the [Prettier's GitHub page](https://github.com/prettier/prettier) for more information, and look at this [page to see it in action](https://prettier.github.io/prettier/).
306 |
307 | To format our code whenever we make a commit in git, we need to install the following dependencies:
308 |
309 | ```sh
310 | npm install --save husky lint-staged prettier
311 | ```
312 |
313 | Alternatively you may use `yarn`:
314 |
315 | ```sh
316 | yarn add husky lint-staged prettier
317 | ```
318 |
319 | - `husky` makes it easy to use githooks as if they are npm scripts.
320 | - `lint-staged` allows us to run scripts on staged files in git. See this [blog post about lint-staged to learn more about it](https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8).
321 | - `prettier` is the JavaScript formatter we will run before commits.
322 |
323 | Now we can make sure every file is formatted correctly by adding a few lines to the `package.json` in the project root.
324 |
325 | Add the following field to the `package.json` section:
326 |
327 | ```diff
328 | + "husky": {
329 | + "hooks": {
330 | + "pre-commit": "lint-staged"
331 | + }
332 | + }
333 | ```
334 |
335 | Next we add a 'lint-staged' field to the `package.json`, for example:
336 |
337 | ```diff
338 | "dependencies": {
339 | // ...
340 | },
341 | + "lint-staged": {
342 | + "src/**/*.{js,jsx,json,css}": [
343 | + "prettier --single-quote --write",
344 | + "git add"
345 | + ]
346 | + },
347 | "scripts": {
348 | ```
349 |
350 | Now, whenever you make a commit, Prettier will format the changed files automatically. You can also run `./node_modules/.bin/prettier --single-quote --write "src/**/*.{js,jsx}"` to format your entire project for the first time.
351 |
352 | Next you might want to integrate Prettier in your favorite editor. Read the section on [Editor Integration](https://prettier.io/docs/en/editors.html) on the Prettier GitHub page.
353 |
354 | ## Changing the Page ``
355 |
356 | You can find the source HTML file in the `public` folder of the generated project. You may edit the `` tag in it to change the title from “React App” to anything else.
357 |
358 | Note that normally you wouldn’t edit files in the `public` folder very often. For example, [adding a stylesheet](#adding-a-stylesheet) is done without touching the HTML.
359 |
360 | If you need to dynamically update the page title based on the content, you can use the browser [`document.title`](https://developer.mozilla.org/en-US/docs/Web/API/Document/title) API. For more complex scenarios when you want to change the title from React components, you can use [React Helmet](https://github.com/nfl/react-helmet), a third party library.
361 |
362 | If you use a custom server for your app in production and want to modify the title before it gets sent to the browser, you can follow advice in [this section](#generating-dynamic-meta-tags-on-the-server). Alternatively, you can pre-build each page as a static HTML file which then loads the JavaScript bundle, which is covered [here](#pre-rendering-into-static-html-files).
363 |
364 | ## Installing a Dependency
365 |
366 | The generated project includes React and ReactDOM as dependencies. It also includes a set of scripts used by Create React App as a development dependency. You may install other dependencies (for example, React Router) with `npm`:
367 |
368 | ```sh
369 | npm install --save react-router-dom
370 | ```
371 |
372 | Alternatively you may use `yarn`:
373 |
374 | ```sh
375 | yarn add react-router-dom
376 | ```
377 |
378 | This works for any library, not just `react-router-dom`.
379 |
380 | ## Importing a Component
381 |
382 | This project setup supports ES6 modules thanks to Webpack.
383 | While you can still use `require()` and `module.exports`, we encourage you to use [`import` and `export`](http://exploringjs.com/es6/ch_modules.html) instead.
384 |
385 | For example:
386 |
387 | ### `Button.js`
388 |
389 | ```js
390 | import React, { Component } from 'react';
391 |
392 | class Button extends Component {
393 | render() {
394 | // ...
395 | }
396 | }
397 |
398 | export default Button; // Don’t forget to use export default!
399 | ```
400 |
401 | ### `DangerButton.js`
402 |
403 | ```js
404 | import React, { Component } from 'react';
405 | import Button from './Button'; // Import a component from another file
406 |
407 | class DangerButton extends Component {
408 | render() {
409 | return ;
410 | }
411 | }
412 |
413 | export default DangerButton;
414 | ```
415 |
416 | Be aware of the [difference between default and named exports](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281). It is a common source of mistakes.
417 |
418 | We suggest that you stick to using default imports and exports when a module only exports a single thing (for example, a component). That’s what you get when you use `export default Button` and `import Button from './Button'`.
419 |
420 | Named exports are useful for utility modules that export several functions. A module may have at most one default export and as many named exports as you like.
421 |
422 | Learn more about ES6 modules:
423 |
424 | - [When to use the curly braces?](http://stackoverflow.com/questions/36795819/react-native-es-6-when-should-i-use-curly-braces-for-import/36796281#36796281)
425 | - [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html)
426 | - [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules)
427 |
428 | ## Code Splitting
429 |
430 | Instead of downloading the entire app before users can use it, code splitting allows you to split your code into small chunks which you can then load on demand.
431 |
432 | This project setup supports code splitting via [dynamic `import()`](http://2ality.com/2017/01/import-operator.html#loading-code-on-demand). Its [proposal](https://github.com/tc39/proposal-dynamic-import) is in stage 3. The `import()` function-like form takes the module name as an argument and returns a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) which always resolves to the namespace object of the module.
433 |
434 | Here is an example:
435 |
436 | ### `moduleA.js`
437 |
438 | ```js
439 | const moduleA = 'Hello';
440 |
441 | export { moduleA };
442 | ```
443 |
444 | ### `App.js`
445 |
446 | ```js
447 | import React, { Component } from 'react';
448 |
449 | class App extends Component {
450 | handleClick = () => {
451 | import('./moduleA')
452 | .then(({ moduleA }) => {
453 | // Use moduleA
454 | })
455 | .catch(err => {
456 | // Handle failure
457 | });
458 | };
459 |
460 | render() {
461 | return (
462 |
463 |
464 |
465 | );
466 | }
467 | }
468 |
469 | export default App;
470 | ```
471 |
472 | This will make `moduleA.js` and all its unique dependencies as a separate chunk that only loads after the user clicks the 'Load' button.
473 |
474 | You can also use it with `async` / `await` syntax if you prefer it.
475 |
476 | ### With React Router
477 |
478 | If you are using React Router check out [this tutorial](http://serverless-stack.com/chapters/code-splitting-in-create-react-app.html) on how to use code splitting with it. You can find the companion GitHub repository [here](https://github.com/AnomalyInnovations/serverless-stack-demo-client/tree/code-splitting-in-create-react-app).
479 |
480 | Also check out the [Code Splitting](https://reactjs.org/docs/code-splitting.html) section in React documentation.
481 |
482 | ## Adding a Stylesheet
483 |
484 | This project setup uses [Webpack](https://webpack.js.org/) for handling all assets. Webpack offers a custom way of “extending” the concept of `import` beyond JavaScript. To express that a JavaScript file depends on a CSS file, you need to **import the CSS from the JavaScript file**:
485 |
486 | ### `Button.css`
487 |
488 | ```css
489 | .Button {
490 | padding: 20px;
491 | }
492 | ```
493 |
494 | ### `Button.js`
495 |
496 | ```js
497 | import React, { Component } from 'react';
498 | import './Button.css'; // Tell Webpack that Button.js uses these styles
499 |
500 | class Button extends Component {
501 | render() {
502 | // You can use them as regular CSS styles
503 | return ;
504 | }
505 | }
506 | ```
507 |
508 | **This is not required for React** but many people find this feature convenient. You can read about the benefits of this approach [here](https://medium.com/seek-blog/block-element-modifying-your-javascript-components-d7f99fcab52b). However you should be aware that this makes your code less portable to other build tools and environments than Webpack.
509 |
510 | In development, expressing dependencies this way allows your styles to be reloaded on the fly as you edit them. In production, all CSS files will be concatenated into a single minified `.css` file in the build output.
511 |
512 | If you are concerned about using Webpack-specific semantics, you can put all your CSS right into `src/index.css`. It would still be imported from `src/index.js`, but you could always remove that import if you later migrate to a different build tool.
513 |
514 | ## Adding a CSS Modules Stylesheet
515 |
516 | > Note: this feature is available with `react-scripts@2.0.0` and higher.
517 |
518 | This project supports [CSS Modules](https://github.com/css-modules/css-modules) alongside regular stylesheets using the `[name].module.css` file naming convention. CSS Modules allows the scoping of CSS by automatically creating a unique classname of the format `[filename]\_[classname]\_\_[hash]`.
519 |
520 | > **Tip:** Should you want to preprocess a stylesheet with Sass then make sure to [follow the installation instructions](#adding-a-sass-stylesheet) and then change the stylesheet file extension as follows: `[name].module.scss` or `[name].module.sass`.
521 |
522 | CSS Modules let you use the same CSS class name in different files without worrying about naming clashes. Learn more about CSS Modules [here](https://css-tricks.com/css-modules-part-1-need/).
523 |
524 | ### `Button.module.css`
525 |
526 | ```css
527 | .error {
528 | background-color: red;
529 | }
530 | ```
531 |
532 | ### `another-stylesheet.css`
533 |
534 | ```css
535 | .error {
536 | color: red;
537 | }
538 | ```
539 |
540 | ### `Button.js`
541 |
542 | ```js
543 | import React, { Component } from 'react';
544 | import styles from './Button.module.css'; // Import css modules stylesheet as styles
545 | import './another-stylesheet.css'; // Import regular stylesheet
546 |
547 | class Button extends Component {
548 | render() {
549 | // reference as a js object
550 | return ;
551 | }
552 | }
553 | ```
554 |
555 | ### Result
556 |
557 | No clashes from other `.error` class names
558 |
559 | ```html
560 |
561 |