markfinger / python-react

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

Use external bundle #19

Closed WhackoJacko closed 9 years ago

WhackoJacko commented 9 years ago

Hello, Mark! We`ve already discussed it a bit, I want to use django-react with my own bundle, containing all required modules. So I just need to instantiate component, which is in this bundle, with props and render it. Is it possible?

markfinger commented 9 years ago

You'd need to ensure that the bundle exports your component. So the last line of your bundle's entry would be something like module.exports = YourComponent; and then you could call django_react.render.render_component('/absolute/path/to/bundle.js', serialized_props_string).

For rendering components, django-react assumes that it can load a file where the module.exports is equal to the component, so it might be a bit challenging if you're not exposing the component from bundle.

If you have access to the component's source via the filesystem, you could simply pass in an absolute path to it. But if you need to interact with bundles, you could try making a separate bundle just for rendering the component, as long as it exports the component it'll work.

In regards to #4 - although I'm not sure if it's any help on this issue - there's an in-development branch of django-webpack, js-service, which adds support for webpack config files (amongst other things).