react-play icon indicating copy to clipboard operation
react-play copied to clipboard

Load javascript files in production

Open khanetor opened this issue 8 years ago • 2 comments

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.

khanetor avatar Aug 07 '15 02:08 khanetor

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?

ssorallen avatar Aug 10 '15 18:08 ssorallen

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.

khanetor avatar Aug 11 '15 01:08 khanetor