I am looking for an example about combining the four technologies in the title :) I have a working ReactJS application using Play, Scala and WebJars, it's here on GitHub.
Now I would like to add RequireJS, but I'm not sure how to go, especially because it seems to require a different JSXTransformer? If anybody has a pointer (or even a PR) it would be very appreciated.
This is not the easiest thing to do, but I was able to pull it off. I will give you some tips here. I also uploaded my own project to github. This is a very simple snake game built using React and RequireJs. It based on Webjars and Play Framework.
Remember that RequireJs is part of Play Framework. Here's a step by step guide to create React/RequireJs/WebJars/Play integration:
addSbtPlugin("com.github.ddispaltro" % "sbt-reactjs" % "0.5.2")
. This is a plugin which transforms JSXes into JSes and also strips flow types if you want that.@helper.requireJs(core = routes.WebJarAssets.at(WebJarAssets.locate("require.js")).url, module = routes.Assets.at("javascripts/main").url)
. This will add add ascript
tag withdata-main
andsrc
attributes that are used to bootstrap your RequireJs app.Create
react.js
file in yourassets/javascripts
folder:Create
main.jsx
file in yourassets/javascripts
folder:Your standard React component goes to
assets/javascripts/components/YourComponent.jsx
and is defined like standard RequireJs module. Remember to return a React class:I hope that helps. If you have any questions, please let me know.