You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Suggest `serve` for serving the `build` directory
* How to handle it with Node in prod (or other platforms)
* Pretty newline added
* Adjusted default port of static server
* Remove `open` command from output
* Removed constant assignment
* Better explanation for not using having to use a static server
* Cute newline added
* Style nits
Copy file name to clipboardexpand all lines: packages/react-scripts/template/README.md
+25-5
Original file line number
Diff line number
Diff line change
@@ -62,6 +62,8 @@ You can find the most recent version of this guide [here](https://github.com/fac
62
62
-[Developing Components in Isolation](#developing-components-in-isolation)
63
63
-[Making a Progressive Web App](#making-a-progressive-web-app)
64
64
-[Deployment](#deployment)
65
+
-[Static Server](#static-server)
66
+
-[Other Solutions](#other-solutions)
65
67
-[Serving Apps with Client-Side Routing](#serving-apps-with-client-side-routing)
66
68
-[Building for Relative Paths](#building-for-relative-paths)
67
69
-[Azure](#azure)
@@ -1208,14 +1210,30 @@ You can turn your React app into a [Progressive Web App](https://developers.goog
1208
1210
1209
1211
## Deployment
1210
1212
1211
-
`npm run build` creates a `build` directory with a production build of your app. Set up your favourite HTTP server so that a visitor to your site is served `index.html`, and requests to static paths like `/static/js/main.<hash>.js` are served with the contents of the `/static/js/main.<hash>.js` file. For example, Python contains a built-in HTTP server that can serve static files:
1213
+
`npm run build` creates a `build` directory with a production build of your app. Set up your favourite HTTP server so that a visitor to your site is served `index.html`, and requests to static paths like `/static/js/main.<hash>.js` are served with the contents of the `/static/js/main.<hash>.js` file.
1214
+
1215
+
### Static Server
1216
+
1217
+
For environments using [Node](https://nodejs.org/), the easiest way to handle this would be to install [serve](https://github.com/zeit/serve) and let it handle the rest:
1218
+
1219
+
```sh
1220
+
npm install -g serve
1221
+
serve -s build
1222
+
```
1223
+
1224
+
The last command shown above will serve your static site on the port **5000**. Like many of [serve](https://github.com/zeit/serve)’s internal settings, the port can be adjusted using the `-p` or `--port` flags.
1225
+
1226
+
Run this command to get a full list of the options available:
1212
1227
1213
1228
```sh
1214
-
cd build
1215
-
python -m SimpleHTTPServer 9000
1229
+
serve -h
1216
1230
```
1217
1231
1218
-
If you’re using [Node](https://nodejs.org/) and [Express](http://expressjs.com/) as a server, it might look like this:
1232
+
### Other Solutions
1233
+
1234
+
You don’t necessarily need a static server in order to run a Create React App project in production. It works just as fine integrated into an existing dynamic one.
1235
+
1236
+
Here’s a programmatic example using [Node](https://nodejs.org/) and [Express](http://expressjs.com/):
1219
1237
1220
1238
```javascript
1221
1239
constexpress=require('express');
@@ -1231,7 +1249,9 @@ app.get('/', function (req, res) {
1231
1249
app.listen(9000);
1232
1250
```
1233
1251
1234
-
Create React App is not opinionated about your choice of web server. Any static file server will do. The `build` folder with static assets is the only output produced by Create React App.
1252
+
The choice of your server software isn’t important either. Since Create React App is completely platform-agnostic, there’s no need to explicitly use Node.
1253
+
1254
+
The `build` folder with static assets is the only output produced by Create React App.
1235
1255
1236
1256
However this is not quite enough if you use client-side routing. Read the next section if you want to support URLs like `/todos/42` in your single-page app.
0 commit comments