Closed watzon closed 7 years ago
In application.js
//= library
In component.js
if namespaced
var OtherComponent = Namespace.OtherComponent
class Blah extends OtherComponent {
...
}
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.
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.
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!
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?