Vikas Vikas - 1 year ago 110
React JSX Question

Deploying build to production using express server which i compiled using webpack -p

I want to deploy my app to production. I dont know what to do after i build my bundle using webpack -p. How to serve this bundle on production using express node server.

My webpack.config.js file ->
My package.json file ->

Note: npm start is running very fine on localhost. And so i used webpack -p for creating bundle in ./dist folder. Need steps from here.

Also suggestion on better way for deploying is appreciated.

Answer Source

You now need to serve the contents of your dist folder with express, here's a basic implementation which you can use as an example:

Create a file named app.js in your . folder (in the same folder you dist folder is in)


var path = require('path');
var express = require('express');

var app = express();

app.use(express.static(path.join(__dirname, '/dist')));

app.get('/*', function(req, res){
  res.sendfile("index.html", {root: path.join(__dirname, '/dist')});

app.listen(80, function() {
  console.log("BePretty Frontend App is running at localhost: 80")

Then, run node app.js, if you get the EACCES error, run sudo node app.js instead. This runs your production files locally at http://localhost.

If you want to deploy this to somewhere else (for example, heroku you will have to check their instructions.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download