Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Wojtek Pituła
    @Krever
    I need this because I want to configure my project in a away that will allow deployment of static files to any web server(e.g. apache or amazon s3), not only the integrated server sub-project
    S
    @SRGOM
    has anything changed between 1.0.3 and 1.0.5? I have a project in 1.0.3 where I enable the plugin and use only a single setting scalaJsPipeline to get continous compilation. Two things that I need and work are: continuous compilation, and of course, copying. Blindly changing 1.0.3 to 1.0.5 stops the copying part
    Vincent Munier
    @vmunier
    Hi @SRGOM, sbt-web-scalajs stopped calling packageScalaJSLauncher when upgrading to Scala.js v0.6.15 (http://www.scala-js.org/news/2017/03/21/announcing-scalajs-0.6.15/#persistlauncher-is-deprecated-in-favor-of-scalajsusemainmoduleinitializer).
    Try adding scalaJSUseMainModuleInitializer := true and removing persistLauncher settings in your build.sbt:
    -  persistLauncher := true,
    -  persistLauncher in Test := false,
    +  scalaJSUseMainModuleInitializer := true
    S
    @SRGOM
    @vmunier Thank you for answering. I tried what you suggested and my code works as it did.
    S
    @SRGOM
    Has anybody here had success with running ensime with a play+scala.js project? I haven't tried but I want to know if spending time will even make sense
    Denis Porfiryev
    @justdanpo
    Hi. Is this room alive?
    Vincent Munier
    @vmunier
    Hi, not many messages, but it's alive.
    Denis Porfiryev
    @justdanpo
    OK, thanks.
    I just wanted to ask for help, I cannot make client part be recompiled on changes automatically. But I realized it doesn't work in Linux but works in Windows :-/
    So it may be a network filesystem issue
    Vincent Munier
    @vmunier
    It should work on Linux too.
    Denis Porfiryev
    @justdanpo
    But it doesn't. Anyway, this is not sbt-web-scalajs issue
    kevinwright
    @kevinwright
    Slightly open question here - trying to determine if this is the right project for my needs
    kevinwright
    @kevinwright
    I have a project targeting NW.js - using scalajs for the logic, and sbt-web to handle staging of public/asset files in /target/web
    Right now I’m using a custom task to also copy the output of fastOptJS to the correct location in that directory
    It looks like set-web-scalajs should be the right way to do it - but the readme file and both demo projects seem to be based exclusively around the idea of a client/server setup, which isn't what I have
    Vincent Munier
    @vmunier
    I have only used sbt-web-scalajs in a client/server setup but there is nothing specific to a HTTP server in sbt-web-scalajs. You could try to use it with NW.js and see if it suits your needs.
    lazy val myNWjs = project.settings(
      scalaJSProjects := Seq(client),
      pipelineStages in Assets := Seq(scalaJSPipeline)
    ).enablePlugins(SbtWeb)
    
    lazy val client = project.enablePlugins(ScalaJSPlugin, ScalaJSWeb)
    kevinwright
    @kevinwright
    I don’t have a separate myNWjs and a client
    There is only client
    my whole world is client
    It just happens to run under NW.js
    kevinwright
    @kevinwright
    So much so that I haven’t even had to define a named project instance in my build.sbt, it’s all just flat settings
    Currently I’m doing this:
    watchSources ++= ((Compile / sourceDirectory).value / "assets" ** "*").get
    
    val fastStage = taskKey[Unit]("Copy all to staging dir")
    val fullStage = taskKey[Unit]("Copy all to staging dir")
    
    def performStage(optJS: TaskKey[Attributed[File]]) = Def.task {
      val tgtPublicDir = (Assets / public).value
      (Assets / assets).value
      val jsDir = tgtPublicDir / "js"
      if (!jsDir.exists) IO.createDirectory(jsDir)
      val tgtFile = jsDir / s"${name.value}.js"
      val jsFile = (Compile / optJS).value.data
      IO.copyFile(jsFile, tgtFile)
    }
    
    fastStage := performStage(fastOptJS).value
    fullStage := performStage(fullOptJS).value
    But it’s not perfect. I’m not sure that it would pick up on the create of a new file in assets if added after I did ~fastStage
    It also doesn’t have the source map handling that sbt-web-scalajs does
    kevinwright
    @kevinwright
    Actually, strike that first point, the watchSources was from before I started using sbt-web, that bit should be good now
    Vincent Munier
    @vmunier

    sbt-web-scalajs will only work if you have separate projects because you need to set the scalaJSProjects setting and you can't self reference your only project. This won't work:

    val client = project.settings(
      scalaJSProjects := Seq(client),  ...
    ).enablePlugins(SbtWeb)

    If you only need to copy fastOptJS output to another directory, it's probably not worth using sbt-web-scalajs in your case.

    moritz bust
    @busti
    Hi,
    where can I find the compiled js files when I run/compile the server project?
    There is nothing in server/target/<etc> after compilation.
    Here is my build.sbt for reference:
    name := "test"
    
    val commonSettings = Seq(
      scalaVersion := "2.12.4",
      version := "1.0"
    )
    
    val http4s = "0.18.0-M9"
    
    lazy val server = (project in file("server"))
      .enablePlugins(SbtWeb)
      .settings(commonSettings)
      .settings(
        scalacOptions ++= Seq("-Ypartial-unification"),
        libraryDependencies ++= Seq(
          "org.http4s"                 %% "http4s-dsl"          % http4s,
          "org.http4s"                 %% "http4s-blaze-server" % http4s,
          "org.http4s"                 %% "http4s-circe"        % http4s,
    
          "ch.qos.logback"             % "logback-classic"      % "1.2.3",
          "com.typesafe.scala-logging" %% "scala-logging"       % "3.7.2"
        ),
        scalaJSProjects := Seq(client),
        pipelineStages in Assets := Seq(scalaJSPipeline),
        compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value
        /*resourceGenerators in Compile += Def.task {
          println("Copying ScalaJS sources...")
          val files = ((crossTarget in(client, Compile)).value ** ("*.js" || "*.map")).get
          val mappings: Seq[(File,String)] = files pair Path.rebase(
            (crossTarget in(client, Compile)).value,
            ((resourceManaged in  Compile).value / "web/js/").getAbsolutePath
          )
          val map: Seq[(File, File)] = mappings.map { case (s, t) => (s, file(t))}
          IO.copy(map).toSeq
        } dependsOn (fastOptJS in(client, Compile))*/
      )
    
    lazy val client = (project in file("client"))
      .enablePlugins(ScalaJSPlugin, ScalaJSWeb)
      .settings(commonSettings)
      .settings(
        scalaJSUseMainModuleInitializer := true,
        libraryDependencies ++= Seq(
          "be.doeraene"   %%% "scalajs-jquery" % "0.9.1",
          "com.lihaoyi"   %%% "scalatags"      % "0.6.7",
          "com.lihaoyi"   %%% "scalarx"        % "0.3.2",
          "com.timushev"  %%% "scalatags-rx"   % "0.3.0"
        ),
        skip in packageJSDependencies := false,
          jsDependencies ++= Seq(
          "org.webjars" % "jquery" % "2.1.4" / "2.1.4/jquery.js",
        )
      )
    
    // loads the server project at sbt startup
    onLoad in Global := (onLoad in Global).value andThen {s: State => "project server" :: s}
    moritz bust
    @busti
    It seems like I forgot to remove my previous method of copying the scalajs files, it is the comment block underneath the sbt-web-scalajs lines
    moritz bust
    @busti
    Is sbt-resolver required for sbt-web-scalajs to work?
    I switched to akka-http, but the scalajs files did not get copied, only after I added sbt-resolver they were copied.
    Vincent Munier
    @vmunier
    Hi, sbt-resolver is not required, you can use run and see the files get copied into the server's target folder. As for your previous build, I have not tried using sbt-web-scalajs with http4s but hopefully, it should not be too different from akka-http.
    moritz bust
    @busti
    @vmunier Thanks a lot for your answer, I am sorry that I didn't reply earlier, a lot has been going on lately.
    I have now switched to akka-http and things are working out perfectly.
    There is just one minor issue, when I try to use ~run on my server project, nothing happens when the client sources change.
    I am using sbt-resolver for that at the moment, but it makes the whole webserver restart each time a source changes which is not ideal.
    Vincent Munier
    @vmunier
    @Busti Indeed, you have to use sbt-resolver (~reStart) with akka-http if you want to see your changes get automatically included. Unfortunately, it restarts the web server, which can be slow, but I don't know any way around it. The experience is a bit better with Play framework: the server does not need to be restarted when an asset file (HTML/CSS, JS, etc.) gets modified but Play has its own auto-reload feature.
    moritz bust
    @busti
    Shouldn't ~compile listen for file changes aswell?
    Vincent Munier
    @vmunier
    It should if if you add compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value to you server's settings. Have a look at https://github.com/vmunier/akka-http-scalajs.g8 for an example (sbt new vmunier/akka-http-scalajs.g8)
    ioleo
    @ioleo
    hello, I've got a problem trying to setup ScalaJS with scalajs-bundler. My config is simmilar to https://github.com/vmunier/akka-http-scalajs.g8/blob/master/src/main/g8/build.sbt however, when I try to serve the assets I'm getting 404 Not found errors at runtime
    import cats.effect.Sync
    import java.io.File
    import org.http4s.{ HttpService, Request, Response, StaticFile }
    import org.http4s.dsl.Http4sDsl
    import org.http4s.dsl.io._
    import org.http4s.twirl._
    import app.html
    
    class SpaController[F[_]: Sync] extends Http4sDsl[F] {
    
      val service: HttpService[F] = HttpService[F] {
        case GET -> Root => Ok(
          html.index("App title")
        )
        case request @ GET -> "assets" /: rest =>
          static(rest, request)
      }
    
      private def static(path: Path, request: Request[F]): F[Response[F]] =
        StaticFile.fromResource(s"public/$path", Some(request)).getOrElseF(NotFound())
    }
    These are my build settings
      lazy val shared = commonSettings ++ Seq(
        name := "intranet-shared",
        libraryDependencies ++= Dependencies.shared.value,
      )
    
      lazy val server = commonSettings ++ Seq(
        name := "intranet-server",
        libraryDependencies ++= Dependencies.server,
        libraryDependencies ++= Dependencies.jvm,
        pipelineStages in Assets := Seq(scalaJSPipeline),
        compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value,
        WebKeys.packagePrefix in Assets := "public/",
        managedClasspath in Runtime += (packageBin in Assets).value,
      )
    
      lazy val client = commonSettings ++ Seq(
        name := "intranet-client",
        mainClass in Compile := Some("app.Application"),
        libraryDependencies ++= Dependencies.client.value,
        npmDependencies in Compile := Dependencies.js,
        npmDevDependencies in Compile := Dependencies.devJs,
        webpackConfigFile in fastOptJS := Some(baseDirectory.value / "dev.webpack.config.js"),
        webpackConfigFile in fullOptJS := Some(baseDirectory.value / "prod.webpack.config.js"),
        scalaJSUseMainModuleInitializer := true,
        scalaJSUseMainModuleInitializer in Test := false,
        jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv,
        webpackBundlingMode := BundlingMode.LibraryOnly(),
      )
    And my build.sbt
    lazy val shared = crossProject(JSPlatform, JVMPlatform)
      .crossType(CrossType.Pure)
      .in(file("shared"))
      .settings(BuildSettings.shared)
      .jsConfigure(_.enablePlugins(ScalaJSWeb, ScalaJSBundlerPlugin))
    
    lazy val sharedJVM = shared.jvm.settings(name := "sharedJVM")
    lazy val sharedJS  = shared.js.settings(name := "sharedJS")
    
    lazy val server = project
      .in(file("server"))
      .settings(BuildSettings.server)
      .settings(scalaJSProjects := Seq(client))
      .enablePlugins(WebScalaJSBundlerPlugin, SbtTwirl, JavaAppPackaging)
      .aggregate(client)
      .dependsOn(sharedJVM)
    
    lazy val client: Project = project
      .in(file("client"))
      .settings(BuildSettings.client)
      .enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin, ScalaJSWeb)
      .dependsOn(sharedJS)
    
    onLoad in Global := (onLoad in Global).value andThen {s: State => "project server" :: s}
    ioleo
    @ioleo
    The requests my front/index page is making are:
    • http://127.0.0.1:8080/assets/intranet-client-fastopt-library.js
    • http://127.0.0.1:8080/assets/intranet-client-fastopt-loader.js
    • http://127.0.0.1:8080/assets/intranet-client-fastopt.js
    I'm wondering where I've made the mistake.
    Vincent Munier
    @vmunier
    I have not tried using sbt-web-scalajs with http4s yet. You should probably try adapting akka-http-scalajs.g8 to work with http4s first, without using scalajs-bundler for now.
    ioleo
    @ioleo
    Is there any sbt command that should list my js assets? So that I can narrow down if the problem is with: files being absent or the way I serve them?
    ioleo
    @ioleo
    Ok, it seems after adding explicit copy task in sbt I can do show compile:managedResources and see my scalajs files ^__^
    import java.nio.file.{Files, StandardCopyOption}
    import com.typesafe.sbt.packager.SettingsHelper._
    
    lazy val server = project
      .in(file("server"))
      .settings(BuildSettings.server)
      .settings(
        scalaJSProjects := Seq(client),
        (Compile / resourceGenerators) += Def.task {
          val webpackFiles = (client / Compile / fullOptJS / webpack).value.map(_.data).filterNot(_.getName contains "bundle")
          val npmFiles = Seq.empty[File]
    
          (webpackFiles ++ npmFiles).map { sourceFile =>
            val targetFile = (Compile / resourceManaged).value / "public" / sourceFile.getName
            Files.createDirectories(targetFile.getParentFile().toPath())
            Files.copy(sourceFile.toPath, targetFile.toPath, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES)
            targetFile
          }
        }.taskValue,
      )
      .enablePlugins(WebScalaJSBundlerPlugin, SbtTwirl, JavaAppPackaging)
      .aggregate(client)
      .dependsOn(sharedJVM)
    its still work in progress (I guess I might need to copy some npm files too), but it's a start
    show compile:managedResources
    [info] client / Compile / managedResources
    [info]     List()
    [info] Compile / managedResources
    [info]     List(/home/user/Projects/intranet/server/target/scala-2.12/resource_managed/main/public/intranet-client-opt.js, /home/user/Projects/intranet/server/target/scala-2.12/resource_managed/main/public/intranet-client-opt-loader.js, /home/user/Projects/intranet/server/target/scala-2.12/resource_managed/main/public/intranet-client-opt-library.js, /home/user/Projects/intranet/server/target/scala-2.12/resource_managed/main/public/intranet-client-opt-library.js.map)
    ioleo
    @ioleo
    and it's working :) I've had some more hiccups with routes (didnt strip the slash), but finally my assets are served :)
    Vincent Munier
    @vmunier
    Nice, good news!
    Ali Akhtar
    @AliAkhtar__twitter
    Hey, I'm trying to follow along the instructions, but I can't get the continuous compile to work. I ran the project using both ~run and ~reStart but if I change the SharedMessages.itWorks content, and refresh the page, it doesn't show the update message unless I ctrl + c and re-run it.
    Ali Akhtar
    @AliAkhtar__twitter
    Using ~reStart causes it to get stuck on "Stopping application server (by killing the forked JVM) ..."