Is it Possible to Run a Webpack/Create-React-App Dev Server *Within* an Express App

338 views Asked by At

I understand that the normal use case for a React/Express app is to run one dev server for your Express app, and one for your React app. My question is, is it at all possible to run the front-end dev server within an Express app, such that:

  • I can start both with node index.js
  • (optional) the two servers share a common port

In other words, is there any way to programmatically start a Webpack dev server from within Node/Javascript (with JS; not using something like execute to run npm start), and if so is there anything special about the create-react-app dev server that would prevent running it programmatically?

EDIT: I found https://github.com/webpack/webpack-dev-middleware, which is almost what I'm looking for. However, it's Webpack, not create-react-app, so while it does allow for hot reloading, it doesn't preserve state between reloads (the way create-react-app's version of Webpack's server does).

So it seems I'm really looking for a create-react-app-dev-server-middleware ... or a way to configure the webpack-dev-middleware to support create-react-app's state preservation between hot reloads.

0

There are 0 answers