markfinger / python-react

Server-side rendering of React components
MIT License
1.62k stars 116 forks source link

Resolve React path from component #31

Closed markfinger closed 9 years ago

markfinger commented 9 years ago

Currently it uses django-react's version, which couples the renderer and the bundler to django-react.

Related: markfinger/render-react#1

mic159 commented 9 years ago

What if you require the module to export React as well as the class?

var React = require('react');
var MyRootComponent = React.createClass({});

module.exports = {React: React, Component: MyRootComponent};

Then in render.js

bundle = require(the_path);
this.component = bundle.Component;
this.react = bundle.React;

That way you dont have to do magic guessing where React.js is.

markfinger commented 9 years ago

That would simplify things on the rendering side, but it introduces more overhead on the developers end.

I suppose you could make an entry module, which simply requires both the component and react, but it's still a bit of overhead that I'd rather avoid.

The renderer used to use https://github.com/substack/node-resolve to pick it up, which meant that React was completely stripped out from the project. That's my pref at this point.

The only complexity in the problem is the bundling process, which tries to omit react, but still needs to know where to require it from during the rendering. It's probably easiest just to require resolve with an abs path and then resolve the path when the renderer requires the config.