-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.sbt
105 lines (97 loc) · 4.38 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import com.alexitc.ChromeSbtPlugin
lazy val appName = "chrome-scalajs-template" // TODO: REPLACE ME
lazy val isProductionBuild = sys.env.getOrElse("PROD", "false") == "true"
Global / onChangedBuildSource := ReloadOnSourceChanges
val circe = "0.14.1"
lazy val baseSettings: Project => Project = {
_.enablePlugins(ScalaJSPlugin)
.settings(
name := appName,
version := "1.0.0",
scalaVersion := "2.13.8",
scalacOptions ++= Seq(
"-language:implicitConversions",
"-language:existentials",
"-Xlint",
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding",
"utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-unchecked" // Enable additional warnings where generated code depends on assumptions.
),
scalacOptions += "-Ymacro-annotations",
Test / requireJsDomEnv := true
)
}
lazy val bundlerSettings: Project => Project = {
_.enablePlugins(ScalaJSBundlerPlugin)
.settings(
useYarn := true,
// NOTE: source maps are disabled to avoid a file not found error which occurs when using the current
// webpack settings.
scalaJSLinkerConfig := scalaJSLinkerConfig.value.withSourceMap(false),
webpack / version := "4.8.1",
// running `sbt test` fails if the webpack config is specified, it seems to happen because
// the default webpack config from scalajs-bundler isn't written, making `sbt test` depend on
// the chromeUnpackedFast task ensures that such config is generated, there might be a better
// solution but this works for now.
Test / test := (Test / test).dependsOn(chromeUnpackedFast).value,
Test / webpackConfigFile := Some(baseDirectory.value / "test.webpack.config.js"),
webpackConfigFile := {
val file = if (isProductionBuild) "production.webpack.config.js" else "dev.webpack.config.js"
Some(baseDirectory.value / file)
},
// scala-js-chrome
scalaJSLinkerConfig := scalaJSLinkerConfig.value.withRelativizeSourceMapBase(
Some((Compile / fastOptJS / artifactPath).value.toURI)
),
packageJSDependencies / skip := false,
webpackBundlingMode := BundlingMode.Application,
fastOptJsLib := (Compile / fastOptJS / webpack).value.head,
fullOptJsLib := (Compile / fullOptJS / webpack).value.head,
webpackBundlingMode := BundlingMode.LibraryAndApplication(),
// you can customize and have a static output name for lib and dependencies
// instead of having the default files names like extension-fastopt.js, ...
Compile / fastOptJS / artifactPath := {
(Compile / fastOptJS / crossTarget).value / "main.js"
},
Compile / fullOptJS / artifactPath := {
(Compile / fullOptJS / crossTarget).value / "main.js"
}
)
}
lazy val buildInfoSettings: Project => Project = {
_.enablePlugins(BuildInfoPlugin)
.settings(
buildInfoPackage := "com.alexitc",
buildInfoKeys := Seq[BuildInfoKey](name),
buildInfoKeys ++= Seq[BuildInfoKey](
"production" -> isProductionBuild,
// it's simpler to propagate the required js scripts from this file to avoid hardcoding
// them on the code that actually injects them.
"activeTabWebsiteScripts" -> AppManifest.manifestActiveTabWebsiteScripts
),
buildInfoUsePackageAsPath := true
)
}
lazy val root = (project in file("."))
.enablePlugins(ChromeSbtPlugin, ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, buildInfoSettings)
.settings(
chromeManifest := AppManifest.generate(appName, Keys.version.value),
// js dependencies, adding typescript type definitions gets them a Scala facade
Compile / npmDependencies ++= Seq(
"sweetalert" -> "2.1.2"
),
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "2.1.0",
"com.alexitc" %%% "scala-js-chrome" % "0.8.1",
"org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0",
"org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0",
"io.circe" %%% "circe-core" % circe,
"io.circe" %%% "circe-generic" % circe,
"io.circe" %%% "circe-parser" % circe,
"org.scalatest" %%% "scalatest" % "3.2.16" % "test"
)
)