lihaoyi / hands-on-scala-js

Better documentation for Scala.js
142 stars 52 forks source link

Fix hands-on-scala-js Client-Server Setup #29

Open MikaelMayer opened 9 years ago

MikaelMayer commented 9 years ago

Before I create a pull request for fixing the issues I encountered while reading this wonderful book, I will put them there so that I can obtain your confirmation they are real issues.

A Client-Server Setup

Add a file project/build.properties containing sbt.version=0.13.7 to ensure that the SBT version is high enough. My sbt version by default is 0.13.0

There is a missing plugin in project/build.sbt which should be added at the end of the file.

addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0-RC1")

Replace in the file Page.scala the first line by the second

script(src := "/appjs-fastopt.js"),
script(src := "/app-fastopt.js"),

Add this to the file Page.scala just before the other script (dependencies)

script(src := "/app-jsdeps.js"),

State the command required to run the server (it took me four hours to figure out, between run, re-start, app/re-start, app/run which had missing main classes, or even start etc., until I figured out I could start sub-projects)

sbt
appJVM/run

Any remarks, or other ways to make this work?

edit; How to integrate sbt resolver:

After some time, I figured out how to configure sbt resolver thanks to your project scala-js-fiddle/blob/master/project/Build.scala.

In the file project/build.sbt, include the following:

addSbtPlugin("io.spray" % "sbt-revolver" % "0.7.2")

In the file /build.sbt, do the following:

.jvmSettings(
   ...
).jvmSettings(
   Revolver.settings:_*
)

Now the application can be started using re-start in sbt directly. I think it can be a valuable point to include in the tutorial.

murmelsson commented 8 years ago

+1 (if that's an acceptable way to promote an issue-report which is also a bugfix-proposal). Agree with the ebook sentiment - as a Scala.js learner, the hands-on ebook is great - still, the book could mention here the appJVM/run "magic spell"-command - i got stuck looking for the right incantation until asked on Gitter https://gitter.im/scala-js/scala-js , where someone kindly pointed it out. And thanks Mikael for pointing out the minor bug in specifying the correct -fastopt.js file in Page.scala, applying your fix was the solution to get the app running.

gtkovas commented 8 years ago

+1. Wasted hours on the various issues in the client-server tutorial, a big detraction from an otherwise great resource. Thank you Mikael for devoting the time to hunt down all the solutions.

mb720 commented 8 years ago

I'm stilling having trouble executing the code of the client-server tutorial. Here's what I tried so far:

  1. Cloned this repo
  2. cd hands-on-scala-js
  3. sbt
  4. clientserver/run and appJVM/run

This yielded:

[warn] No main class detected java.lang.RuntimeException: No main class detected. at scala.sys.package$.error(package.scala:27)

Any help is much appreciated.


Edit:

Never mind, I took Li Haoyi's example and overhauled it: https://github.com/mb720/scalajsClientServer

The project includes instructions on how to start the server (it's easy, though). Also, I used the most recent version of all dependencies (except for spray-can 1.3.3 where I noticed a constant and significant CPU load after the first request from the client). I modified the code a bit when I could make things simpler and when APIs changed or were deprecated.

Feedback is very welcome! :-)