In this section, we'll use the Webpack scaffold we developed in Chapter 6, Advanced React. We'll need to add a few packages and make some modifications.
As a reminder, this is the file structure of our scaffold before we start:
├── assets │ ├── app.css │ ├── favicon.ico │ └── index.html ├── package.json ├── server.js ├── source │ └── index.jsx └── webpack.config.js
Let's start by renaming our server.js
file to server-development.js
. Then, create a new file called server-production.js
in the root of the scaffold and add this code:
'use strict'; var path = require('path'); var express = require('express'); var serveStatic = require('serve-static') var compression = require('compression') var port = process.env.PORT || 8080; var host = process.env.HOST || '0.0.0.0';
Here, we instruct the server to use the preconfigured variables for PORT
and HOST
or the default variables if these aren't provided, just as we did with the Browserify server. Then, we add...