-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
77 lines (69 loc) · 3.46 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
Global / onChangedBuildSource := IgnoreSourceChanges // not working well with webpack devserver
name := "Blend"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "3.1.2"
val versions = new {
val outwatch = "1.0.0-RC8"
val funPack = "0.2.0"
val scalaTest = "3.2.11"
}
ThisBuild / resolvers ++= Seq(
"jitpack" at "https://jitpack.io",
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
"Sonatype OSS Snapshots S01" at "https://s01.oss.sonatype.org/content/repositories/snapshots", // https://central.sonatype.org/news/20210223_new-users-on-s01/
)
lazy val scalaJsMacrotaskExecutor = Seq(
// https://github.com/scala-js/scala-js-macrotask-executor
libraryDependencies += "org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0",
Compile / npmDependencies += "setimmediate" -> "1.0.5", // polyfill
stIgnore += "setimmediate",
)
def readJsDependencies(baseDirectory: File, field: String): Seq[(String, String)] = {
val packageJson = ujson.read(IO.read(new File(s"$baseDirectory/package.json")))
packageJson(field).obj.mapValues(_.str.toString).toSeq
}
lazy val webapp = project
.enablePlugins(
ScalaJSPlugin,
ScalaJSBundlerPlugin,
ScalablyTypedConverterPlugin,
)
.settings(scalaJsMacrotaskExecutor)
.settings(
libraryDependencies ++= Seq(
"io.github.outwatch" %%% "outwatch" % versions.outwatch,
"io.github.outwatch" %%% "outwatch-util" % versions.outwatch,
"org.scalatest" %%% "scalatest" % versions.scalaTest % Test,
),
Compile / npmDependencies ++= readJsDependencies(baseDirectory.value, "dependencies") ++ Seq(
"snabbdom" -> "github:outwatch/snabbdom.git#semver:0.7.5", // for outwatch, workaround for: https://github.com/ScalablyTyped/Converter/issues/293
),
stIgnore ++= List(
"snabbdom",
),
Compile / npmDependencies ++= readJsDependencies(baseDirectory.value, "dependencies"),
Compile / npmDevDependencies ++= readJsDependencies(baseDirectory.value, "devDependencies"),
scalacOptions --= Seq(
"-Xfatal-warnings",
), // overwrite option from https://github.com/DavidGregory084/sbt-tpolecat
useYarn := true, // Makes scalajs-bundler use yarn instead of npm
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.CommonJSModule)
}, // configure Scala.js to emit a JavaScript module instead of a top-level script
scalaJSUseMainModuleInitializer := true, // On Startup, call the main function
webpackDevServerPort := 12345,
webpack / version := "4.46.0",
startWebpackDevServer / version := "3.11.3",
webpackDevServerExtraArgs := Seq("--color"),
fullOptJS / webpackEmitSourceMaps := true,
fastOptJS / webpackBundlingMode := BundlingMode
.LibraryOnly(), // https://scalacenter.github.io/scalajs-bundler/cookbook.html#performance
fastOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack.config.dev.js"),
fullOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack.config.prod.js"),
/* Test / requireJsDomEnv := true, */
)
addCommandAlias("prod", "fullOptJS/webpack")
addCommandAlias("dev", "devInit; devWatchAll; devDestroy")
addCommandAlias("devInit", "; webapp/fastOptJS/startWebpackDevServer")
addCommandAlias("devWatchAll", "~; webapp/fastOptJS/webpack")
addCommandAlias("devDestroy", "webapp/fastOptJS/stopWebpackDevServer")