├── .dockerignore
├── .gitignore
├── .travis.yml
├── Dockerfile
├── LICENSE
├── README.md
├── api
├── .babelrc
├── package-lock.json
├── package.json
└── src
│ ├── index.js
│ └── wsHandler.js
├── appveyor-build.ps1
├── appveyor-deploy.ps1
├── appveyor.yml
├── client
├── .editorconfig
├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
│ ├── custom.css
│ ├── favicon.ico
│ ├── index.html
│ ├── manifest.json
│ └── theme.min.css
└── src
│ ├── actions
│ ├── appInit.js
│ ├── closeTaskDetailsModal.js
│ ├── displayTaskDetailsModal.js
│ ├── index.js
│ ├── setNodes.js
│ ├── setServices.js
│ ├── setTasks.js
│ └── websocket.js
│ ├── components
│ ├── App.js
│ ├── App.test.js
│ ├── ConnectionIndicator.js
│ ├── ConnectionStatus.js
│ ├── Header.js
│ └── nodes
│ │ ├── FormRow.js
│ │ ├── ImageName.js
│ │ ├── NodeEntryDisplay.js
│ │ ├── NodeView.js
│ │ ├── ServiceDetails.js
│ │ ├── ServiceName.js
│ │ ├── TaskEntryDisplay.js
│ │ ├── TaskInfoModal.js
│ │ ├── TaskView.css
│ │ └── TaskView.js
│ ├── index.js
│ ├── logo.svg
│ ├── middleware
│ ├── appInitialization.js
│ ├── index.js
│ └── updater.js
│ ├── reducers
│ ├── index.js
│ ├── swarmState.js
│ ├── taskDetailsModal.js
│ └── webSocket.js
│ ├── registerServiceWorker.js
│ └── util
│ ├── ReconnectingWebSocket.js
│ ├── apiClient.js
│ ├── constants.js
│ └── store.js
├── docker-compose.yml
├── docs
├── screenshot1.png
└── screenshot2.png
├── swarm-viz.dockerapp
├── docker-compose.yml
├── metadata.yml
└── settings.yml
├── travis-build.sh
└── travis-deploy.sh
/.dockerignore:
--------------------------------------------------------------------------------
1 | dist
2 | build
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (https://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # Typescript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | build
61 | dist
62 | .DS_Store
63 | .idea
64 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: required
2 |
3 | services:
4 | - docker
5 |
6 | env:
7 | matrix:
8 | - ARCH=amd64
9 | - ARCH=s390x
10 |
11 | script:
12 | - ./travis-build.sh
13 | - >
14 | if [ "$TRAVIS_BRANCH" == "master" -a "$TRAVIS_PULL_REQUEST" == "false" ]; then
15 | # push image on master and non-pull-request builds
16 | travis_retry timeout 5m docker login -u="$DOCKER_USER" -p="$DOCKER_PASS"
17 | ./travis-deploy.sh
18 | fi
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | ARG node=node:8.7-alpine
2 | ARG target=node:8.7-alpine
3 |
4 | # Build frontend
5 | FROM $node as frontend
6 | WORKDIR /app
7 | COPY client/package.json .
8 | RUN npm install --quiet
9 | COPY client/ .
10 | RUN npm run build
11 |
12 | # Build backend
13 | FROM $node as backend
14 | WORKDIR /app
15 | COPY api/package.json .
16 | RUN npm install --quiet
17 | COPY api/ .
18 | RUN npm run build
19 |
20 | # Put them together
21 | FROM $node as proddeps
22 | WORKDIR /app
23 | COPY api/package.json .
24 | RUN npm install --production --quiet
25 | COPY --from=backend /app/dist /app/dist
26 | COPY --from=frontend /app/build /app/build
27 |
28 | FROM $target
29 | EXPOSE 3000
30 | COPY --from=proddeps /app /app
31 | CMD ["node", "/app/dist/index.js"]
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2017. Michael Irwin
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Swarm Visualizer
2 |
3 | 
4 | 
5 |
6 | This project is serving as an updated version of the Swarm Visualizer found at https://github.com/dockersamples/docker-swarm-visualizer.
7 |
8 | 
9 |
10 | 
11 |
12 |
13 | ## Why another one?
14 |
15 | - It's event driven (well, sorta... tasks don't generate events yet, but we'll ignore that for now)
16 | - Less clutter. Only the essential details are present, but more details are available with just a click
17 | - Allows for more than three nodes. Have more nodes? It'll just keep adding another row!
18 |
19 |
20 | ## Running the visualizer
21 |
22 | ### Linux/Mac
23 |
24 | Running as container:
25 |
26 | ```
27 | docker container run \
28 | --name swarm-viz \
29 | -p 3000:3000 \
30 | -v /var/run/docker.sock:/var/run/docker.sock \
31 | mikesir87/swarm-viz
32 | ```
33 |
34 | ### Windows Server 1709
35 |
36 | Run as Windows container:
37 |
38 | ```
39 | docker container run `
40 | --name swarm-viz `
41 | -p 3000:3000 `
42 | -u ContainerAdministrator `
43 | -v //./pipe/docker_engine://./pipe/docker_engine `
44 | mikesir87/swarm-viz
45 | ```
46 |
47 | ## Development
48 |
49 | From the root directory, simply run
50 |
51 | ```
52 | docker-compose up -d
53 | ```
54 |
55 | The backend (api) is found in the `/api` directory and the frontend is found in the `/client` directory.
56 |
57 | ## Build
58 |
59 | ### Windows
60 |
61 | At the moment there is no official node image for Windows. Therefore apply another base image to build the app.
62 |
63 | ```
64 | docker build -t mikesir87/swarm-viz --build-arg node=stefanscherer/node-windows:1709 .
65 | ```
66 |
--------------------------------------------------------------------------------
/api/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["es2015", "stage-2"],
3 | "plugins": [
4 | ["transform-runtime", {
5 | "polyfill": false,
6 | "regenerator": true
7 | }]
8 | ]
9 | }
--------------------------------------------------------------------------------
/api/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "swarm-visualizer-api",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "private": true,
7 | "scripts": {
8 | "test": "echo \"Error: no test specified\" && exit 1",
9 | "build": "babel src --out-dir dist",
10 | "build-watch": "nodemon --watch src --exec babel src --out-dir dist",
11 | "dev": "concurrently \"npm run build-watch\" \"npm run serve-watch\"",
12 | "serve-watch": "nodemon dist/index.js"
13 | },
14 | "author": "",
15 | "license": "ISC",
16 | "dependencies": {
17 | "babel-runtime": "^6.26.0",
18 | "dockerode": "^2.5.2",
19 | "express": "^4.16.2",
20 | "express-ws": "^3.0.0",
21 | "ws": "^3.2.0"
22 | },
23 | "devDependencies": {
24 | "babel-cli": "^6.26.0",
25 | "babel-plugin-transform-runtime": "^6.23.0",
26 | "babel-polyfill": "^6.26.0",
27 | "babel-preset-es2015": "^6.24.1",
28 | "babel-preset-stage-2": "^6.24.1",
29 | "concurrently": "^3.5.0",
30 | "nodemon": "^1.12.1"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/api/src/index.js:
--------------------------------------------------------------------------------
1 | import express from "express";
2 | import expressWs from "express-ws";
3 | import {createWsHandler} from "./wsHandler";
4 | import Docker from "dockerode";
5 |
6 | const app = express();
7 | const appWs = expressWs(app);
8 | const dockerAgent = new Docker();
9 |
10 | app.use(express.static("/app/build"));
11 |
12 | app.ws("/api/events", createWsHandler(appWs));
13 |
14 | app.get("/api/nodes", async (req, res) => {
15 | const nodes = await dockerAgent.listNodes();
16 | res.json(nodes);
17 | });
18 |
19 | app.get("/api/services", async (req, res) => {
20 | const services = await dockerAgent.listServices();
21 | res.json(services);
22 | });
23 |
24 | app.get("/api/tasks", async(req, res) => {
25 | const tasks = await dockerAgent.listTasks();
26 | res.json(tasks);
27 | });
28 |
29 | app.listen(3000, () => console.log("App listening on port 3000"));
30 |
31 | //
32 | // need this in docker container to properly exit since node doesn't handle
33 | // SIGINT/SIGTERM
34 | // Note, a more graceful way would be first server.close(), wait X seconds for
35 | // connections to close (but websockets), then process.exit()
36 | //
37 |
38 | process
39 | .on('SIGTERM', shutdown('SIGTERM')) // docker stop
40 | .on('SIGINT', shutdown('SIGINT')) // ctrl-c in linux/mac
41 | .on('uncaughtException', shutdown('uncaughtException'));
42 |
43 | // shut down server without waiting
44 | function shutdown(signal) {
45 | return (err) => {
46 | console.log(`${ signal }...`);
47 | if (err) console.error(err.stack || err);
48 | setTimeout(() => {
49 | process.exit(err ? 1 : 0);
50 | }, 0).unref();
51 | };
52 | }
53 |
--------------------------------------------------------------------------------
/api/src/wsHandler.js:
--------------------------------------------------------------------------------
1 | import Docker from "dockerode";
2 | const crypto = require("crypto");
3 | const dockerAgent = new Docker();
4 |
5 | export function createWsHandler(wsApp) {
6 | dockerAgent.getEvents({
7 | filters : {
8 | type : [ "node", "service" ]
9 | }
10 | }).then((stream) => {
11 | stream.on("data", (chunk) => {
12 | const data = chunk.toString("utf8");
13 | wsApp.getWss().clients.forEach((client) => {
14 | client.send(data);
15 | });
16 | });
17 | });
18 |
19 | let lastTaskHash = "";
20 | async function pollTasks() {
21 | const tasks = await dockerAgent.listTasks();
22 | let taskHash = crypto.createHash("md5").update(JSON.stringify(tasks)).digest("hex");
23 | if (taskHash === lastTaskHash)
24 | return;
25 | lastTaskHash = taskHash;
26 |
27 | const message = JSON.stringify({ type : "task.update", payload : tasks });
28 | wsApp.getWss().clients.forEach((client) => {
29 | client.send(message);
30 | });
31 | }
32 |
33 | setInterval(pollTasks, 500);
34 |
35 | return (ws, req) => {
36 | console.log("New WebSocket connection");
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/appveyor-build.ps1:
--------------------------------------------------------------------------------
1 | $ErrorActionPreference = 'Stop';
2 | $files = ""
3 | Write-Host Starting build
4 |
5 | Write-Host Updating base images
6 |
7 | docker build -t mikesir87/swarm-viz --build-arg node=stefanscherer/node-windows:1709 --build-arg target=stefanscherer/node-windows:1709 .
8 | docker images
9 |
--------------------------------------------------------------------------------
/appveyor-deploy.ps1:
--------------------------------------------------------------------------------
1 | $ErrorActionPreference = 'Stop';
2 |
3 | Write-Host Starting deploy
4 | docker login -u="$env:DOCKER_USER" -p="$env:DOCKER_PASS"
5 |
6 | docker tag mikesir87/swarm-viz mikesir87/swarm-viz:windows-amd64-$env:APPVEYOR_REPO_COMMIT
7 | docker push mikesir87/swarm-viz:windows-amd64-$env:APPVEYOR_REPO_COMMIT
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: 1.0.{build}
2 | image: Visual Studio 2017
3 |
4 | build_script:
5 | - ps: .\appveyor-build.ps1
6 |
7 | deploy_script:
8 | - ps: >-
9 | docker login -u="$env:DOCKER_USER" -p="$env:DOCKER_PASS"
10 | .\appveyor-deploy.ps1
--------------------------------------------------------------------------------
/client/.editorconfig:
--------------------------------------------------------------------------------
1 | [*]
2 | end_of_line = lf
3 | insert_final_newline = true
4 |
5 | [*.{js,ts}]
6 | charset = utf-8
7 | indent_style = space
8 | indent_size = 2
9 |
--------------------------------------------------------------------------------
/client/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/ignore-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 |
--------------------------------------------------------------------------------
/client/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React App](https://github.com/facebookincubator/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/facebookincubator/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 Language Features and Polyfills](#supported-language-features-and-polyfills)
17 | - [Syntax Highlighting in the Editor](#syntax-highlighting-in-the-editor)
18 | - [Displaying Lint Output in the Editor](#displaying-lint-output-in-the-editor)
19 | - [Debugging in the Editor](#debugging-in-the-editor)
20 | - [Formatting Code Automatically](#formatting-code-automatically)
21 | - [Changing the Page `
`](#changing-the-page-title)
22 | - [Installing a Dependency](#installing-a-dependency)
23 | - [Importing a Component](#importing-a-component)
24 | - [Code Splitting](#code-splitting)
25 | - [Adding a Stylesheet](#adding-a-stylesheet)
26 | - [Post-Processing CSS](#post-processing-css)
27 | - [Adding a CSS Preprocessor (Sass, Less etc.)](#adding-a-css-preprocessor-sass-less-etc)
28 | - [Adding Images, Fonts, and Files](#adding-images-fonts-and-files)
29 | - [Using the `public` Folder](#using-the-public-folder)
30 | - [Changing the HTML](#changing-the-html)
31 | - [Adding Assets Outside of the Module System](#adding-assets-outside-of-the-module-system)
32 | - [When to Use the `public` Folder](#when-to-use-the-public-folder)
33 | - [Using Global Variables](#using-global-variables)
34 | - [Adding Bootstrap](#adding-bootstrap)
35 | - [Using a Custom Theme](#using-a-custom-theme)
36 | - [Adding Flow](#adding-flow)
37 | - [Adding Custom Environment Variables](#adding-custom-environment-variables)
38 | - [Referencing Environment Variables in the HTML](#referencing-environment-variables-in-the-html)
39 | - [Adding Temporary Environment Variables In Your Shell](#adding-temporary-environment-variables-in-your-shell)
40 | - [Adding Development Environment Variables In `.env`](#adding-development-environment-variables-in-env)
41 | - [Can I Use Decorators?](#can-i-use-decorators)
42 | - [Integrating with an API Backend](#integrating-with-an-api-backend)
43 | - [Node](#node)
44 | - [Ruby on Rails](#ruby-on-rails)
45 | - [Proxying API Requests in Development](#proxying-api-requests-in-development)
46 | - ["Invalid Host Header" Errors After Configuring Proxy](#invalid-host-header-errors-after-configuring-proxy)
47 | - [Configuring the Proxy Manually](#configuring-the-proxy-manually)
48 | - [Configuring a WebSocket Proxy](#configuring-a-websocket-proxy)
49 | - [Using HTTPS in Development](#using-https-in-development)
50 | - [Generating Dynamic `` Tags on the Server](#generating-dynamic-meta-tags-on-the-server)
51 | - [Pre-Rendering into Static HTML Files](#pre-rendering-into-static-html-files)
52 | - [Injecting Data from the Server into the Page](#injecting-data-from-the-server-into-the-page)
53 | - [Running Tests](#running-tests)
54 | - [Filename Conventions](#filename-conventions)
55 | - [Command Line Interface](#command-line-interface)
56 | - [Version Control Integration](#version-control-integration)
57 | - [Writing Tests](#writing-tests)
58 | - [Testing Components](#testing-components)
59 | - [Using Third Party Assertion Libraries](#using-third-party-assertion-libraries)
60 | - [Initializing Test Environment](#initializing-test-environment)
61 | - [Focusing and Excluding Tests](#focusing-and-excluding-tests)
62 | - [Coverage Reporting](#coverage-reporting)
63 | - [Continuous Integration](#continuous-integration)
64 | - [Disabling jsdom](#disabling-jsdom)
65 | - [Snapshot Testing](#snapshot-testing)
66 | - [Editor Integration](#editor-integration)
67 | - [Developing Components in Isolation](#developing-components-in-isolation)
68 | - [Getting Started with Storybook](#getting-started-with-storybook)
69 | - [Getting Started with Styleguidist](#getting-started-with-styleguidist)
70 | - [Making a Progressive Web App](#making-a-progressive-web-app)
71 | - [Opting Out of Caching](#opting-out-of-caching)
72 | - [Offline-First Considerations](#offline-first-considerations)
73 | - [Progressive Web App Metadata](#progressive-web-app-metadata)
74 | - [Analyzing the Bundle Size](#analyzing-the-bundle-size)
75 | - [Deployment](#deployment)
76 | - [Static Server](#static-server)
77 | - [Other Solutions](#other-solutions)
78 | - [Serving Apps with Client-Side Routing](#serving-apps-with-client-side-routing)
79 | - [Building for Relative Paths](#building-for-relative-paths)
80 | - [Azure](#azure)
81 | - [Firebase](#firebase)
82 | - [GitHub Pages](#github-pages)
83 | - [Heroku](#heroku)
84 | - [Netlify](#netlify)
85 | - [Now](#now)
86 | - [S3 and CloudFront](#s3-and-cloudfront)
87 | - [Surge](#surge)
88 | - [Advanced Configuration](#advanced-configuration)
89 | - [Troubleshooting](#troubleshooting)
90 | - [`npm start` doesn’t detect changes](#npm-start-doesnt-detect-changes)
91 | - [`npm test` hangs on macOS Sierra](#npm-test-hangs-on-macos-sierra)
92 | - [`npm run build` exits too early](#npm-run-build-exits-too-early)
93 | - [`npm run build` fails on Heroku](#npm-run-build-fails-on-heroku)
94 | - [`npm run build` fails to minify](#npm-run-build-fails-to-minify)
95 | - [Moment.js locales are missing](#momentjs-locales-are-missing)
96 | - [Something Missing?](#something-missing)
97 |
98 | ## Updating to New Releases
99 |
100 | Create React App is divided into two packages:
101 |
102 | * `create-react-app` is a global command-line utility that you use to create new projects.
103 | * `react-scripts` is a development dependency in the generated projects (including this one).
104 |
105 | You almost never need to update `create-react-app` itself: it delegates all the setup to `react-scripts`.
106 |
107 | 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.
108 |
109 | To update an existing project to a new version of `react-scripts`, [open the changelog](https://github.com/facebookincubator/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.
110 |
111 | In most cases bumping the `react-scripts` version in `package.json` and running `npm install` in this folder should be enough, but it’s good to consult the [changelog](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md) for potential breaking changes.
112 |
113 | We commit to keeping the breaking changes minimal so you can upgrade `react-scripts` painlessly.
114 |
115 | ## Sending Feedback
116 |
117 | We are always open to [your feedback](https://github.com/facebookincubator/create-react-app/issues).
118 |
119 | ## Folder Structure
120 |
121 | After creation, your project should look like this:
122 |
123 | ```
124 | my-app/
125 | README.md
126 | node_modules/
127 | package.json
128 | public/
129 | index.html
130 | favicon.ico
131 | src/
132 | App.css
133 | App.js
134 | App.test.js
135 | index.css
136 | index.js
137 | logo.svg
138 | ```
139 |
140 | For the project to build, **these files must exist with exact filenames**:
141 |
142 | * `public/index.html` is the page template;
143 | * `src/index.js` is the JavaScript entry point.
144 |
145 | You can delete or rename the other files.
146 |
147 | You may create subdirectories inside `src`. For faster rebuilds, only files inside `src` are processed by Webpack.
148 | You need to **put any JS and CSS files inside `src`**, otherwise Webpack won’t see them.
149 |
150 | Only files inside `public` can be used from `public/index.html`.
151 | Read instructions below for using assets from JavaScript and HTML.
152 |
153 | You can, however, create more top-level directories.
154 | They will not be included in the production build so you can use them for things like documentation.
155 |
156 | ## Available Scripts
157 |
158 | In the project directory, you can run:
159 |
160 | ### `npm start`
161 |
162 | Runs the app in the development mode.
163 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
164 |
165 | The page will reload if you make edits.
166 | You will also see any lint errors in the console.
167 |
168 | ### `npm test`
169 |
170 | Launches the test runner in the interactive watch mode.
171 | See the section about [running tests](#running-tests) for more information.
172 |
173 | ### `npm run build`
174 |
175 | Builds the app for production to the `build` folder.
176 | It correctly bundles React in production mode and optimizes the build for the best performance.
177 |
178 | The build is minified and the filenames include the hashes.
179 | Your app is ready to be deployed!
180 |
181 | See the section about [deployment](#deployment) for more information.
182 |
183 | ### `npm run eject`
184 |
185 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
186 |
187 | 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.
188 |
189 | 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.
190 |
191 | 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.
192 |
193 | ## Supported Language Features and Polyfills
194 |
195 | This project supports a superset of the latest JavaScript standard.
196 | In addition to [ES6](https://github.com/lukehoban/es6features) syntax features, it also supports:
197 |
198 | * [Exponentiation Operator](https://github.com/rwaldron/exponentiation-operator) (ES2016).
199 | * [Async/await](https://github.com/tc39/ecmascript-asyncawait) (ES2017).
200 | * [Object Rest/Spread Properties](https://github.com/sebmarkbage/ecmascript-rest-spread) (stage 3 proposal).
201 | * [Dynamic import()](https://github.com/tc39/proposal-dynamic-import) (stage 3 proposal)
202 | * [Class Fields and Static Properties](https://github.com/tc39/proposal-class-public-fields) (part of stage 3 proposal).
203 | * [JSX](https://facebook.github.io/react/docs/introducing-jsx.html) and [Flow](https://flowtype.org/) syntax.
204 |
205 | Learn more about [different proposal stages](https://babeljs.io/docs/plugins/#presets-stage-x-experimental-presets-).
206 |
207 | While we recommend to use 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.
208 |
209 | Note that **the project only includes a few ES6 [polyfills](https://en.wikipedia.org/wiki/Polyfill)**:
210 |
211 | * [`Object.assign()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) via [`object-assign`](https://github.com/sindresorhus/object-assign).
212 | * [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) via [`promise`](https://github.com/then/promise).
213 | * [`fetch()`](https://developer.mozilla.org/en/docs/Web/API/Fetch_API) via [`whatwg-fetch`](https://github.com/github/fetch).
214 |
215 | 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, or that the browsers you are targeting already support them.
216 |
217 | ## Syntax Highlighting in the Editor
218 |
219 | 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.
220 |
221 | ## Displaying Lint Output in the Editor
222 |
223 | >Note: this feature is available with `react-scripts@0.2.0` and higher.
224 | >It also only works with npm 3 or higher.
225 |
226 | Some editors, including Sublime Text, Atom, and Visual Studio Code, provide plugins for ESLint.
227 |
228 | 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.
229 |
230 | You would need to install an ESLint plugin for your editor first. Then, add a file called `.eslintrc` to the project root:
231 |
232 | ```js
233 | {
234 | "extends": "react-app"
235 | }
236 | ```
237 |
238 | Now your editor should report the linting warnings.
239 |
240 | 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.
241 |
242 | If you want to enforce a coding style for your project, consider using [Prettier](https://github.com/jlongster/prettier) instead of ESLint style rules.
243 |
244 | ## Debugging in the Editor
245 |
246 | **This feature is currently only supported by [Visual Studio Code](https://code.visualstudio.com) and [WebStorm](https://www.jetbrains.com/webstorm/).**
247 |
248 | 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.
249 |
250 | ### Visual Studio Code
251 |
252 | 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.
253 |
254 | Then add the block below to your `launch.json` file and put it inside the `.vscode` folder in your app’s root directory.
255 |
256 | ```json
257 | {
258 | "version": "0.2.0",
259 | "configurations": [{
260 | "name": "Chrome",
261 | "type": "chrome",
262 | "request": "launch",
263 | "url": "http://localhost:3000",
264 | "webRoot": "${workspaceRoot}/src",
265 | "userDataDir": "${workspaceRoot}/.vscode/chrome",
266 | "sourceMapPathOverrides": {
267 | "webpack:///src/*": "${webRoot}/*"
268 | }
269 | }]
270 | }
271 | ```
272 | >Note: the URL may be different if you've made adjustments via the [HOST or PORT environment variables](#advanced-configuration).
273 |
274 | 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.
275 |
276 | ### WebStorm
277 |
278 | 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.
279 |
280 | 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.
281 |
282 | >Note: the URL may be different if you've made adjustments via the [HOST or PORT environment variables](#advanced-configuration).
283 |
284 | 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.
285 |
286 | The same way you can debug your application in IntelliJ IDEA Ultimate, PhpStorm, PyCharm Pro, and RubyMine.
287 |
288 | ## Formatting Code Automatically
289 |
290 | 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/).
291 |
292 | To format our code whenever we make a commit in git, we need to install the following dependencies:
293 |
294 | ```sh
295 | npm install --save husky lint-staged prettier
296 | ```
297 |
298 | Alternatively you may use `yarn`:
299 |
300 | ```sh
301 | yarn add husky lint-staged prettier
302 | ```
303 |
304 | * `husky` makes it easy to use githooks as if they are npm scripts.
305 | * `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).
306 | * `prettier` is the JavaScript formatter we will run before commits.
307 |
308 | Now we can make sure every file is formatted correctly by adding a few lines to the `package.json` in the project root.
309 |
310 | Add the following line to `scripts` section:
311 |
312 | ```diff
313 | "scripts": {
314 | + "precommit": "lint-staged",
315 | "start": "react-scripts start",
316 | "build": "react-scripts build",
317 | ```
318 |
319 | Next we add a 'lint-staged' field to the `package.json`, for example:
320 |
321 | ```diff
322 | "dependencies": {
323 | // ...
324 | },
325 | + "lint-staged": {
326 | + "src/**/*.{js,jsx,json,css}": [
327 | + "prettier --single-quote --write",
328 | + "git add"
329 | + ]
330 | + },
331 | "scripts": {
332 | ```
333 |
334 | 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.
335 |
336 | Next you might want to integrate Prettier in your favorite editor. Read the section on [Editor Integration](https://github.com/prettier/prettier#editor-integration) on the Prettier GitHub page.
337 |
338 | ## Changing the Page ``
339 |
340 | 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.
341 |
342 | 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.
343 |
344 | 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.
345 |
346 | 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).
347 |
348 | ## Installing a Dependency
349 |
350 | 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`:
351 |
352 | ```sh
353 | npm install --save react-router
354 | ```
355 |
356 | Alternatively you may use `yarn`:
357 |
358 | ```sh
359 | yarn add react-router
360 | ```
361 |
362 | This works for any library, not just `react-router`.
363 |
364 | ## Importing a Component
365 |
366 | This project setup supports ES6 modules thanks to Babel.
367 | 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.
368 |
369 | For example:
370 |
371 | ### `Button.js`
372 |
373 | ```js
374 | import React, { Component } from 'react';
375 |
376 | class Button extends Component {
377 | render() {
378 | // ...
379 | }
380 | }
381 |
382 | export default Button; // Don’t forget to use export default!
383 | ```
384 |
385 | ### `DangerButton.js`
386 |
387 |
388 | ```js
389 | import React, { Component } from 'react';
390 | import Button from './Button'; // Import a component from another file
391 |
392 | class DangerButton extends Component {
393 | render() {
394 | return ;
395 | }
396 | }
397 |
398 | export default DangerButton;
399 | ```
400 |
401 | 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.
402 |
403 | 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'`.
404 |
405 | 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.
406 |
407 | Learn more about ES6 modules:
408 |
409 | * [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)
410 | * [Exploring ES6: Modules](http://exploringjs.com/es6/ch_modules.html)
411 | * [Understanding ES6: Modules](https://leanpub.com/understandinges6/read#leanpub-auto-encapsulating-code-with-modules)
412 |
413 | ## Code Splitting
414 |
415 | 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.
416 |
417 | 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.
418 |
419 | Here is an example:
420 |
421 | ### `moduleA.js`
422 |
423 | ```js
424 | const moduleA = 'Hello';
425 |
426 | export { moduleA };
427 | ```
428 | ### `App.js`
429 |
430 | ```js
431 | import React, { Component } from 'react';
432 |
433 | class App extends Component {
434 | handleClick = () => {
435 | import('./moduleA')
436 | .then(({ moduleA }) => {
437 | // Use moduleA
438 | })
439 | .catch(err => {
440 | // Handle failure
441 | });
442 | };
443 |
444 | render() {
445 | return (
446 |
447 |
448 |
449 | );
450 | }
451 | }
452 |
453 | export default App;
454 | ```
455 |
456 | This will make `moduleA.js` and all its unique dependencies as a separate chunk that only loads after the user clicks the 'Load' button.
457 |
458 | You can also use it with `async` / `await` syntax if you prefer it.
459 |
460 | ### With React Router
461 |
462 | 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).
463 |
464 | ## Adding a Stylesheet
465 |
466 | 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**:
467 |
468 | ### `Button.css`
469 |
470 | ```css
471 | .Button {
472 | padding: 20px;
473 | }
474 | ```
475 |
476 | ### `Button.js`
477 |
478 | ```js
479 | import React, { Component } from 'react';
480 | import './Button.css'; // Tell Webpack that Button.js uses these styles
481 |
482 | class Button extends Component {
483 | render() {
484 | // You can use them as regular CSS styles
485 | return ;
486 | }
487 | }
488 | ```
489 |
490 | **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-ui-engineering/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.
491 |
492 | 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.
493 |
494 | 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.
495 |
496 | ## Post-Processing CSS
497 |
498 | This project setup minifies your CSS and adds vendor prefixes to it automatically through [Autoprefixer](https://github.com/postcss/autoprefixer) so you don’t need to worry about it.
499 |
500 | For example, this:
501 |
502 | ```css
503 | .App {
504 | display: flex;
505 | flex-direction: row;
506 | align-items: center;
507 | }
508 | ```
509 |
510 | becomes this:
511 |
512 | ```css
513 | .App {
514 | display: -webkit-box;
515 | display: -ms-flexbox;
516 | display: flex;
517 | -webkit-box-orient: horizontal;
518 | -webkit-box-direction: normal;
519 | -ms-flex-direction: row;
520 | flex-direction: row;
521 | -webkit-box-align: center;
522 | -ms-flex-align: center;
523 | align-items: center;
524 | }
525 | ```
526 |
527 | If you need to disable autoprefixing for some reason, [follow this section](https://github.com/postcss/autoprefixer#disabling).
528 |
529 | ## Adding a CSS Preprocessor (Sass, Less etc.)
530 |
531 | Generally, we recommend that you don’t reuse the same CSS classes across different components. For example, instead of using a `.Button` CSS class in `` and `` components, we recommend creating a `