Setup & Configuration

Quick Setup with Giter8

You can create an sbt based Tyrian project and have it up and running in less than 5 minutes!*

From your command line, create a folder for your project, navigate into it, and run:

sbt new PurpleKingdomGames/tyrian.g8

Then follow the instructions in the README file.

(* Probably, if you have sbt and npm/yarn already installed… 😅)

Installation

Tyrian is a Scala 3 Web UI library, so please set your Scala version to 3.2.0 or higher.

You can use Tyrian with Scala 2 thanks to cross versions and the magic of TASTy.

Please note that both the sbt and Mill instructions below assume you intend to work with some sort of web packager/bundler, and therefore emit common js modules.

The examples in the Tyrian repo almost all use Parcel.js as the bundler.

sbt

Add the Scala.js plugin to your project/plugins.sbt file.

addSbtPlugin("org.scala-js" % "sbt-scalajs"  % "1.11.0")

Enable the plugin and add the Tyrian library to your build.sbt file.

At the time of writing, only an implementation for Cats Effect 3’s IO exists, only because no other compatible libs were available. In theory however, Tyrian will support any effectful monad that implements the CE3 typeclasses. If you’d like to do that, take a look at the tiny implementation, and import tyrian instead of tyrian-io shown below.

enablePlugins(ScalaJSPlugin)

libraryDependencies ++= Seq(
  "io.indigoengine" %%% "tyrian-io" % "0.6.0"
)

scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) }

Optionally, you can also include the Tyrian/Indigo Bridge library if you plan to embed an Indigo game in your page:

libraryDependencies ++= Seq(
  ...
  "io.indigoengine" %%% "tyrian-indigo-bridge" % "0.6.0"
)

Mill

Below is a complete, basic Mill build.sc file including MUnit for testing.

import $ivy.`com.lihaoyi::mill-contrib-bloop:$MILL_VERSION`
import mill._
import mill.scalalib._
import mill.scalajslib._
import mill.scalajslib.api._

object counter extends ScalaJSModule {
  def scalaVersion   = "3.2.0"
  def scalaJSVersion = "1.11.0"

  def ivyDeps = Agg(ivy"io.indigoengine::tyrian::0.6.0")

  override def moduleKind = T(mill.scalajslib.api.ModuleKind.CommonJSModule)

  object test extends Tests {
    def ivyDeps = Agg(ivy"org.scalameta::munit::0.7.29")

    def testFramework = "munit.Framework"

    override def moduleKind = T(mill.scalajslib.api.ModuleKind.CommonJSModule)
    override def jsEnvConfig = T(
      JsEnvConfig.NodeJs(args = List("--dns-result-order=ipv4first"))
    )
  }

}

Optionally, you can also include the Tyrian/Indigo Bridge library if you plan to embed an Indigo game in your page:

  def ivyDeps = Agg(
    ivy"io.indigoengine::tyrian::0.6.0",
    ivy"io.indigoengine::tyrian-indigo-bridge::0.6.0"
  )