score:3

Accepted answer

you will have to use a jsx compilation plugin that you can use to compile .jsx files into .js, for example this: https://github.com/ddispaltro/sbt-reactjs

you will then need to use different import blocks in your templates depending on if running as in dev or prod, something like this:

@if(play.api.play.current.mode == play.api.mode.prod) {
  <script src="@routes.assets.at("lib/react/react.js")" type="text/javascript" ></script>
  <script src="@routes.assets.at("javascripts/reactapp.js")" type="text/jsx"></script>
} else {
  <script src="@routes.assets.at("lib/react/react.js")" type="text/javascript" ></script>
  <script src="@routes.assets.at("lib/react/jsxtransformer.js")" type="text/javascript" ></script>
  <script src="@routes.assets.at("javascripts/reactapp.jsx")" type="text/jsx"></script>
}

more elaborate setups can be achieved using requirejs and other module managing schemes, but this is the simplest solution in a small project imho.


Related Query

More Query from same tag