Git Product home page Git Product logo

Comments (2)

vmunier avatar vmunier commented on May 27, 2024

Hi!

  • Enabling ScalaJSWeb is enough to make the build work, since it already includes ScalaJSPlugin. However, one may want to specify their own version of Scala.js and not depend on the Scala.js version included with sbt-web-scalajs.
  • .jsConfigure(_.enablePlugins(ScalaJSWeb)) is needed to configure sourcemaps on the shared project. Let's say you remove .jsConfigure(_.enablePlugins(ScalaJSWeb)) and make the following modifications:
// SharedMessages.scala
object SharedMessages {
  def itWorks = "It works!"
  def exception = throw new Exception("Hey!")
}
// ScalaJSExample.scala
...
  def main(args: Array[String]): Unit = {
    dom.document.getElementById("scalajsShoutOut").textContent = SharedMessages.itWorks
    SharedMessages.exception
  }

then run the project:

$ sbt
sbt> <root>/clean
sbt> server/run

open localhost:9000 in a browser (preferably in an incognito window to be sure the cache is empty). You can open the Web Console and hover SharedMessages.scala:5. It should display file:///.../SharedMessages.scala:5, i.e. it's using the file:// protocol, which is fine when running the project locally as the file exists on your machine, but it will not work when deploying to a server where the file will not exist on that local path.
Conversely, when keeping .jsConfigure(_.enablePlugins(ScalaJSWeb)), the link should be http://localhost:9000/versionedAssets/.../SharedMessages.scala:5, i.e. fetching the Scala file from the Play server (Scala file that was packaged by ScalaJSWeb). This method works both locally and on a remote server.

from play-scalajs.g8.

marcgrue avatar marcgrue commented on May 27, 2024

Thanks for the thorough explanation and amendments! It all makes sense to me now.

from play-scalajs.g8.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.