Skip to content

Instantly share code, notes, and snippets.

@elyphas
Created July 4, 2018 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elyphas/665cfed7db5d247cc252541b1d5749e6 to your computer and use it in GitHub Desktop.
Save elyphas/665cfed7db5d247cc252541b1d5749e6 to your computer and use it in GitHub Desktop.
import sbt.Keys._
import sbt.Project.projectToRef
// a special crossProject for configuring a JS/JVM/shared structure
lazy val shared = (crossProject.crossType(CrossType.Pure) in file("shared"))
.settings(
scalaVersion := Settings.versions.scala,
libraryDependencies ++= Settings.sharedDependencies.value
)
// set up settings specific to the JS project
.jsConfigure(_ enablePlugins ScalaJSWeb)
lazy val sharedJVM = shared.jvm.settings(name := "sharedJVM")
lazy val sharedJS = shared.js.settings(name := "sharedJS")
// use eliding to drop some debug code in the production build
lazy val elideOptions = settingKey[Seq[String]]("Set limit for elidable functions")
// instantiate the JS project for SBT with some additional settings
lazy val client: Project = (project in file("client"))
.settings(
name := "client",
version := Settings.version,
scalaVersion := Settings.versions.scala,
scalacOptions ++= Settings.scalacOptions,
libraryDependencies ++= Settings.scalajsDependencies.value,
// by default we do development build, no eliding
elideOptions := Seq(),
scalacOptions ++= elideOptions.value,
jsDependencies ++= Settings.jsDependencies.value,
// RuntimeDOM is needed for tests
jsDependencies += RuntimeDOM % "test",
// yes, we want to package JS dependencies
skip in packageJSDependencies := false,
// use Scala.js provided launcher code to start the client app
scalaJSUseMainModuleInitializer := true,
scalaJSUseMainModuleInitializer in Test := false,
// use uTest framework for tests
testFrameworks += new TestFramework("utest.runner.Framework")
)
.enablePlugins(ScalaJSPlugin, ScalaJSWeb, SbtWeb)
.dependsOn(sharedJS)
// Client projects (just one in this case)
lazy val clients = Seq(client)
// instantiate the JVM project for SBT with some additional settings
lazy val server = (project in file("server"))
.settings(
name := "server",
version := Settings.version,
scalaVersion := Settings.versions.scala,
scalacOptions ++= Settings.scalacOptions,
libraryDependencies ++= Settings.jvmDependencies.value :+ guice :+ ws,
commands += ReleaseCmd,
// triggers scalaJSPipeline when using compile or continuous compilation
compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value,
// connect to the client project
scalaJSProjects := clients,
pipelineStages in Assets := Seq(scalaJSPipeline),
pipelineStages := Seq(digest, gzip),
// compress CSS
LessKeys.compress in Assets := true
//,
//javaOptions in run += "-Xms256M -Xmx2G" //-XX:MaxPermSize=1024M
)
.enablePlugins(PlayScala)
.disablePlugins(PlayLayoutPlugin) // use the standard directory layout instead of Play's custom
.aggregate(clients.map(projectToRef): _*)
.dependsOn(sharedJVM)
// Command for building a release
lazy val ReleaseCmd = Command.command("release") {
state => "set elideOptions in client := Seq(\"-Xelide-below\", \"WARNING\")" ::
"client/clean" ::
"client/test" ::
"server/clean" ::
"server/test" ::
"server/dist" ::
"set elideOptions in client := Seq()" ::
state
}
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)
onLoad in Global ~= (_ andThen ("project server" :: _))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment