Skip to content

Instantly share code, notes, and snippets.

@malteneuss
Created April 27, 2021 10:01
Show Gist options
  • Save malteneuss/7e93ffbdcc70414f788be5f823b0d662 to your computer and use it in GitHub Desktop.
Save malteneuss/7e93ffbdcc70414f788be5f823b0d662 to your computer and use it in GitHub Desktop.
sbt multi-project Scala with Scalajs and sbt-web-scalajs-bundler plugin example
ThisBuild / organization := "com.org"
ThisBuild / scalaVersion := "2.13.5"
ThisBuild / version := "0.1.0-SNAPSHOT"
cancelable in Global := true
lazy val root = (project in file("."))
.aggregate(server, client, sharedJvm, sharedJs)
lazy val server = (project in file("server"))
.settings(
scalaJSProjects := Seq(client),
Assets / pipelineStages := Seq(scalaJSPipeline),
pipelineStages := Seq(digest, gzip),
// triggers scalaJSPipeline when using compile or continuous compilation
Compile / compile := ((Compile / compile) dependsOn scalaJSPipeline).value,
libraryDependencies ++= Seq(
"com.vmunier" %% "scalajs-scripts" % "1.1.4",
guice,
specs2 % Test
)
)
.enablePlugins(PlayScala)
.enablePlugins(WebScalaJSBundlerPlugin)
.dependsOn(sharedJvm)
lazy val client = (project in file("client"))
.settings(
scalaJSUseMainModuleInitializer := true,
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "1.1.0"
)
)
.enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin)
.dependsOn(sharedJs)
lazy val shared = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.in(file("shared"))
.jsConfigure(_.enablePlugins(ScalaJSBundlerPlugin))
.jsSettings(
Compile / npmDependencies ++= Seq(
// "react-router-dom" -> "5.1.2",
// "@types/react-router-dom" -> "5.1.2"
)
)
lazy val sharedJvm = shared.jvm
lazy val sharedJs = shared.js
// ..
addSbtPlugin("com.vmunier" % "sbt-web-scalajs" % "1.1.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.1")
addSbtPlugin("ch.epfl.scala" % "sbt-web-scalajs-bundler" % "0.20.0")
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment