paypal / react-engine

a composite render engine for universal (isomorphic) express apps to render both plain react views and react-router views
Apache License 2.0
1.45k stars 130 forks source link

Bringing react engine in existing express app. #137

Open reggi opened 8 years ago

reggi commented 8 years ago

I'm trying to wrap all of react-engine and my small react app in a module that can easily be used in another larger express app for example if you export the app variable at the end of this file example/server.js and rename that file react-code.js then make another file server.js with something like this:

import reactCode from './react-code'
import express from 'express';
let app = express();

app.use(reactCode)

const PORT = 3000;

const server = app.listen(PORT, function() {
  console.log('Example app listening at http://localhost:%s', PORT);
});

I can easily move around the react piece in a larger express app (ignore that theres a * glob assigned to every route in the example).

The thing I'm having a more hard time including in this modularity is the webpack integration. I was wondering if it was possible to use webpack programmatically and given env flags a piece of middleware could render .bundle.js and serve it directly from express instead of having webpack render a file in a specific public folder. The fixed public folder, and the webpack script prevents a react-engine route / express app from being easily encapsulated.

Wondering general thoughts on this. I'm trying to compartmentalize / organize the react-engine-app portion of a greater app, without too much overhead on integrating webpack.

reggi commented 8 years ago

I have a demo of how I'm encapsulating a the react-engine in this gist. I'm calling it react-engine-wrapper.js, could be useful to other people.

samsel commented 8 years ago

:+1: