reactjs / react-rails

Integrate React.js with Rails views and controllers, the asset pipeline, or webpacker.
Apache License 2.0
6.75k stars 759 forks source link

A conversation about using require() #284

Closed watzon closed 7 years ago

watzon commented 9 years ago

I know that this has been brought up before, but I figured I'd reach out and see if any new solutions have popped up since then. So let's hear it. Has anyone found a fairly easy-to-implement solution for requiring external component libraries in react-rails?

krzysiek1507 commented 9 years ago

In application.js

//= library

In component.js if namespaced

var OtherComponent = Namespace.OtherComponent

class Blah extends OtherComponent {
 ...
}
danott commented 9 years ago

Using https://rails-assets.org/ for external libs has worked well in my practice. The caveat being, those packages have to be on bower.

The approach I've started taking for things that are not on bower is to build my own browserify'd or webpack'd version of the other component. A readme for how to do that could be a interim solution.

Others' mileage may very, but overall, sticking with Sprockets has been the happiest path I've taken. I've tried browserify-rails, and also built my own webpack_rails solution, but at the end of day, embracing Sprockets with all it's warts works wonderfully if I accept the trade-offs.

AndrewRayCode commented 9 years ago

this project is fundamentally incompatible with a require() workflow https://github.com/reactjs/react-rails/issues/129 as the authors have stated they are sticking with the rails asset pipeline. The mentioned https://github.com/reactjs/react-rails/issues/120 gives a hairy hack that might work for commonjs.

rmosolgo commented 7 years ago

As mentioned, there's nothing in this gem to especially support require. I'll be keeping an eye out for asset changes in 5.1, where webpack may come in the mix!