To create a production build you need to run the command npm run build
. It will create the build
folder, that contains the production build files. Now you just need to upload the build
files on to the server.
Static Server:
For environments using Node, the easiest way to handle this would be to install serve and let it handle the rest:
npm install -g serve serve -s build
Other Solutions:
You don’t necessarily need a static server in order to run a project in production. It works just as fine integrated into an existing dynamic one.
Here’s a programmatic example using Node and Express:
const express = require('express'); const path = require('path'); const app = express(); app.use(express.static(path.join(__dirname, 'build'))); app.get('/', function (req, res) { res.sendFile(path.join(__dirname, 'build', 'index.html')); }); app.listen(9000);
Apache HTTP server:
If you’re using Apache HTTP Server, you need to create a .htaccess
file in the public
folder that looks like this:
Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.html [QSA,L]
Upload the build
files in the public folder.