Skip to content

Instantly share code, notes, and snippets.

@jkleckner
Last active September 18, 2015 22:01
Show Gist options
  • Save jkleckner/26867e841f133d07807d to your computer and use it in GitHub Desktop.
Save jkleckner/26867e841f133d07807d to your computer and use it in GitHub Desktop.
Edited scalajs-spa-tutorial build.sbt for eclipse settings
import sbt.Credentials
import sbt.Keys._
import sbt.Project.projectToRef
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
resolvers ++= Settings.resolvers.value
// 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,
resolvers ++= Settings.resolvers.value
, credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
)
// set up settings specific to the JS project
.jsConfigure(_ enablePlugins ScalaJSPlay)
.jsSettings(
sourceMapsBase := baseDirectory.value / "..",
EclipseKeys.useProjectId := true
)
lazy val sharedJVM = shared.jvm
lazy val sharedJS = shared.js
// 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,
resolvers ++= Settings.resolvers.value,
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"),
// 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",
// use Scala.js provided launcher code to start the client app
persistLauncher := true,
persistLauncher in Test := false,
// must specify source maps location because we use pure CrossProject
sourceMapsDirectories += sharedJS.base / "..",
// yes, we want to package JS dependencies
skip in packageJSDependencies := false,
// use uTest framework for tests
testFrameworks += new TestFramework("utest.runner.Framework")
)
.enablePlugins(ScalaJSPlugin, ScalaJSPlay)
.dependsOn(sharedJS)
// Client projects (just one)
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,
resolvers ++= Settings.resolvers.value,
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"),
commands += ReleaseCmd,
// connect to the client project
scalaJSProjects := clients,
pipelineStages := Seq(scalaJSProd),
// compress CSS
LessKeys.compress in Assets := true,
// set environment variables in the execute scripts
NativePackagerKeys.batScriptExtraDefines += "set PRODUCTION_MODE=true",
NativePackagerKeys.bashScriptExtraDefines += "export PRODUCTION_MODE=true",
EclipseKeys.skipParents in ThisBuild := false
)
.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
}
// loads the Play server project at sbt startup
onLoad in Global := (Command.process("project server", _: State)) compose (onLoad in Global).value
// for Eclipse users
EclipseKeys.skipParents in ThisBuild := false
// Compile the project before generating Eclipse files, so that generated .scala or .class files for views and routes are present
EclipseKeys.preTasks := Seq(compile in (server, Compile))
@jkleckner
Copy link
Author

The server shouldn't have .dependsOn(sharedJS) on L88 (since removed) and the problem compilation happens without it present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment