-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
84 lines (78 loc) · 2.87 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
lazy val commonSettings = {
organization := "org.http4s"
version := "0.0.1-SNAPSHOT"
scalaVersion := "2.12.2"
}
val Http4sVersion = "0.17.0-M2"
val utestV = "0.4.5"
val scalaJsDomV = "0.9.1"
// This function allows triggered compilation to run only when scala files changes
// It lets change static files freely
def includeInTrigger(f: java.io.File): Boolean =
f.isFile && {
val name = f.getName.toLowerCase
name.endsWith(".scala") || name.endsWith(".js")
}
lazy val shared =
(crossProject.crossType(CrossType.Pure) in file("shared"))
.settings(commonSettings)
.settings(
libraryDependencies ++= Seq(
"com.lihaoyi" %%% "scalatags" % "0.6.5",
"co.fs2" %%% "fs2-core" % "0.9.7",
"co.fs2" %%% "fs2-cats" % "0.3.0",
"org.typelevel" %%% "cats" % "0.9.0"
)
)
lazy val sharedJvm = shared.jvm
lazy val sharedJs = shared.js
lazy val backend = (project in file("backend"))
.settings(
name := "backend"
)
.settings(commonSettings)
.settings(
libraryDependencies ++= Seq(
"org.http4s" %% "http4s-blaze-server" % Http4sVersion,
"org.http4s" %% "http4s-circe" % Http4sVersion,
"org.http4s" %% "http4s-dsl" % Http4sVersion,
"ch.qos.logback" % "logback-classic" % "1.2.3"
),
// Allows to read the generated JS on client
resources in Compile += (fastOptJS in (frontend, Compile)).value.data,
// Lets the backend to read the .map file for js
resources in Compile += (fastOptJS in (frontend, Compile)).value
.map((x: sbt.File) => new File(x.getAbsolutePath + ".map"))
.data,
// Lets the server read the jsdeps file
(managedResources in Compile) += (artifactPath in (frontend, Compile, packageJSDependencies)).value,
// do a fastOptJS on reStart
reStart := (reStart dependsOn (fastOptJS in (frontend, Compile))).evaluated,
// This settings makes reStart to rebuild if a scala.js file changes on the client
watchSources ++= (watchSources in frontend).value,
// On recompilation only consider changes to .scala and .js files
watchSources ~= { t: Seq[java.io.File] =>
{ t.filter(includeInTrigger) }
}
)
.dependsOn(sharedJvm)
lazy val frontend = (project in file("frontend"))
.settings(
name := "frontend"
)
.enablePlugins(ScalaJSPlugin)
.settings(commonSettings: _*)
.settings(
// Requires the DOM
jsDependencies += RuntimeDOM,
// Build a js dependencies file
skip in packageJSDependencies := false,
// Put the jsdeps file on a place reachable for the server
crossTarget in (Compile, packageJSDependencies) := (resourceManaged in Compile).value,
testFrameworks += new TestFramework("utest.runner.Framework"),
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % scalaJsDomV,
"com.lihaoyi" %%% "utest" % utestV % Test
)
)
.dependsOn(sharedJs)