124 lines
3.9 KiB
Scala
124 lines
3.9 KiB
Scala
import org.scalajs.linker.interface.ModuleSplitStyle
|
|
import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._
|
|
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}
|
|
|
|
ThisBuild / scalaVersion := "3.7.1"
|
|
ThisBuild / scalacOptions += "-Xfatal-warnings"
|
|
ThisBuild / scalacOptions += "-Wunused:imports"
|
|
|
|
// Root project
|
|
lazy val root = project
|
|
.in(file("."))
|
|
.aggregate(sharedJs, browser, nodejs)
|
|
.settings(
|
|
name := "fahrtenbuch",
|
|
publish := {},
|
|
publishLocal := {}
|
|
)
|
|
|
|
// Shared code project
|
|
lazy val shared = crossProject(JSPlatform)
|
|
.crossType(CrossType.Pure)
|
|
.in(file("shared"))
|
|
.settings(
|
|
libraryDependencies ++= Seq(
|
|
"de.tu-darmstadt.stg" %%% "rdts" % "0.37.0",
|
|
"org.getshaka" %%% "native-converter" % "0.9.0"
|
|
)
|
|
)
|
|
.jsSettings(
|
|
// JS-specific settings for shared code
|
|
)
|
|
|
|
lazy val sharedJs = shared.js
|
|
|
|
// Browser-specific project
|
|
lazy val browser = project
|
|
.in(file("browser"))
|
|
.enablePlugins(
|
|
ScalaJSPlugin,
|
|
ScalablyTypedConverterExternalNpmPlugin
|
|
)
|
|
.dependsOn(sharedJs)
|
|
.settings(
|
|
name := "fahrtenbuch-browser",
|
|
|
|
// Tell Scala.js that this is an application with a main method
|
|
scalaJSUseMainModuleInitializer := true,
|
|
|
|
// scalably typed config
|
|
// Ignore several Trystero dependencies in ScalablyTyped to avoid `stImport` errors
|
|
stIgnore := List(
|
|
"libp2p",
|
|
"firebase",
|
|
"@supabase/supabase-js",
|
|
"@mdi/font",
|
|
"bulma",
|
|
"node"
|
|
),
|
|
externalNpm := baseDirectory.value.getParentFile,
|
|
|
|
/* Configure Scala.js to emit modules in the optimal way to
|
|
* connect to Vite's incremental reload.
|
|
* - emit ECMAScript modules
|
|
* - emit as many small modules as possible for classes in the "fahrtenbuch" package
|
|
* - emit as few (large) modules as possible for all other classes
|
|
* (in particular, for the standard library)
|
|
*/
|
|
scalaJSLinkerConfig ~= {
|
|
_.withModuleKind(ModuleKind.ESModule)
|
|
.withModuleSplitStyle(
|
|
ModuleSplitStyle.SmallModulesFor(List("fahrtenbuch"))
|
|
)
|
|
},
|
|
|
|
/* Browser-specific dependencies */
|
|
libraryDependencies ++= Seq(
|
|
"org.scala-js" %%% "scalajs-dom" % "2.8.0",
|
|
"com.raquo" %%% "laminar" % "17.2.1",
|
|
"de.tu-darmstadt.stg" %%% "rdts" % "0.37.0",
|
|
"org.getshaka" %%% "native-converter" % "0.9.0"
|
|
),
|
|
|
|
// Output directory for browser build
|
|
Compile / fastOptJS / crossTarget := baseDirectory.value.getParentFile / "dist" / "browser",
|
|
Compile / fullOptJS / crossTarget := baseDirectory.value.getParentFile / "dist" / "browser"
|
|
)
|
|
|
|
// Node.js-specific project
|
|
lazy val nodejs = project
|
|
.in(file("nodejs"))
|
|
.enablePlugins(ScalaJSPlugin)
|
|
.dependsOn(sharedJs)
|
|
.settings(
|
|
name := "fahrtenbuch-nodejs",
|
|
|
|
// Tell Scala.js that this is an application with a main method
|
|
scalaJSUseMainModuleInitializer := true,
|
|
|
|
/* Configure Scala.js for Node.js
|
|
* - emit CommonJS modules for Node.js compatibility
|
|
* - optimize for Node.js runtime
|
|
*/
|
|
scalaJSLinkerConfig ~= {
|
|
_.withModuleKind(ModuleKind.CommonJSModule)
|
|
.withModuleSplitStyle(ModuleSplitStyle.FewestModules)
|
|
},
|
|
|
|
/* Node.js-specific dependencies */
|
|
libraryDependencies ++= Seq(
|
|
"de.tu-darmstadt.stg" %%% "rdts" % "0.37.0",
|
|
"org.getshaka" %%% "native-converter" % "0.9.0"
|
|
),
|
|
|
|
// Output directory for Node.js build
|
|
Compile / fastOptJS / crossTarget := baseDirectory.value.getParentFile / "dist" / "nodejs",
|
|
Compile / fullOptJS / crossTarget := baseDirectory.value.getParentFile / "dist" / "nodejs",
|
|
|
|
// Use .cjs extension for CommonJS compatibility
|
|
Compile / fastOptJS / artifactPath := (Compile / fastOptJS / crossTarget).value / "main.cjs",
|
|
Compile / fullOptJS / artifactPath := (Compile / fullOptJS / crossTarget).value / "main.cjs"
|
|
)
|
|
|
|
// Global settings
|
|
Global / onChangedBuildSource := ReloadOnSourceChanges
|