react-play
react-play copied to clipboard
Load javascript files in production
Have you ever tested in production? After you run sbt stage
, all the assets are no longer available at val a = getClass.getResourceAsStream("target/web/public/main/javascripts/bundle.js")
, but instead packaged in a jar file.
Thanks for pointing that out. I tried this only locally and not in production mode. Are you familiar with accessing those files once they've been packaged?
You can view my whole project here.
Basically I load the scripts from public assets like this:
val vendors = Play.application.resourceAsStream("public/javascripts/vendors.js")
val serverSideComponent = Play.application.resourceAsStream("public/javascripts/serverSide.js")
val vendorsReader = new InputStreamReader(vendors.get)
val serverSideComponentReader = new InputStreamReader(serverSideComponent.get)
Note that I use npm webpack, and my precompile js files are in the private
directory. Build with webpack and you will get the scripts in the public
directory.