All Projects → vmunier → Sbt Web Scalajs

vmunier / Sbt Web Scalajs

Licence: apache-2.0
SBT plugin to use Scala.js along with any sbt-web server.

Programming Languages

scala
5932 projects
scalajs
39 projects

Labels

Projects that are alternatives of or similar to Sbt Web Scalajs

Sbt S3 Resolver
☁️Amazon S3-based resolver for sbt
Stars: ✭ 112 (-39.46%)
Mutual labels:  sbt
Sbt Native Image
Plugin to generate native-image binaries with sbt
Stars: ✭ 128 (-30.81%)
Mutual labels:  sbt
Sbt Docker Compose
Integrates Docker Compose functionality into sbt
Stars: ✭ 168 (-9.19%)
Mutual labels:  sbt
Sbt Jacoco
JaCoCo Code Coverage plug-in for sbt.
Stars: ✭ 115 (-37.84%)
Mutual labels:  sbt
Setup Scala
GitHub Action to install any version of Java (GraalVM, Java 8, Java 11, Java 14, ...) via Jabba. Works for any JVM language including Java, Scala and Kotlin.
Stars: ✭ 123 (-33.51%)
Mutual labels:  sbt
Scala Ts
🔧 Scala to TypeScript code generator
Stars: ✭ 152 (-17.84%)
Mutual labels:  sbt
Sbt Prompt
An SBT plugin for making your SBT prompt more awesome
Stars: ✭ 107 (-42.16%)
Mutual labels:  sbt
Sbt Crossproject
Cross-platform compilation support for sbt.
Stars: ✭ 176 (-4.86%)
Mutual labels:  sbt
Sbt Multi Project Example
sbt multi-project example
Stars: ✭ 124 (-32.97%)
Mutual labels:  sbt
Sbt Site
Site generation for sbt
Stars: ✭ 166 (-10.27%)
Mutual labels:  sbt
Scalafx Ensemble
scalafx ensemble
Stars: ✭ 116 (-37.3%)
Mutual labels:  sbt
Mqperf
Stars: ✭ 122 (-34.05%)
Mutual labels:  sbt
Sample Projects
Sample project files for JavaCPP, JavaCPP Presets, and JavaCV
Stars: ✭ 160 (-13.51%)
Mutual labels:  sbt
Sbt Unidoc
sbt plugin to create a unified API document across projects
Stars: ✭ 113 (-38.92%)
Mutual labels:  sbt
Jitpack.io
Documentation and issues of https://jitpack.io
Stars: ✭ 2,156 (+1065.41%)
Mutual labels:  sbt
Sbt Native Packager
sbt Native Packager
Stars: ✭ 1,480 (+700%)
Mutual labels:  sbt
Gatling Sbt Plugin Demo
Showcase of the Gatling Plugin for SBT
Stars: ✭ 137 (-25.95%)
Mutual labels:  sbt
Scala Play React Seed
❄️ Java Play 2.7.x + React seed project with full-fledged build process
Stars: ✭ 180 (-2.7%)
Mutual labels:  sbt
Sbt Doctest
Doctest for scala
Stars: ✭ 171 (-7.57%)
Mutual labels:  sbt
Sbt Protobuf
sbt plugin for compiling protobuf files
Stars: ✭ 163 (-11.89%)
Mutual labels:  sbt

sbt-web-scalajs

License Download Gitter

sbt-web-scalajs is a SBT plugin which allows you to use Scala.js along with any sbt-web server. It uses the sbt-web and scala-js plugins.

Setup

Specify the sbt version in project/build.properties, which needs to be 0.13.16 or higher (or sbt 1.x):

sbt.version=1.3.10

If you want to use Scala.js 1.x, add the following plugins to project/plugins.sbt:

addSbtPlugin("com.vmunier" % "sbt-web-scalajs" % "1.1.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.1.0")

Otherwise, if you prefer using Scala.js 0.6.x, add the following plugins to project/plugins.sbt:

addSbtPlugin("com.vmunier" % "sbt-web-scalajs" % "1.1.0-0.6")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.33")

Lastly, put the following configuration in build.sbt:

lazy val server = project.settings(
  scalaJSProjects := Seq(client),
  pipelineStages in Assets := Seq(scalaJSPipeline)
).enablePlugins(SbtWeb)

lazy val client = project.enablePlugins(ScalaJSPlugin, ScalaJSWeb)

Note: make sure you use the Assets scope.

Examples

To see the plugin in action, you can run sbt new with one of these Giter8 templates:

Upgrade to v1.1.0

Have a look at the sbt-web-scalajs v1.1.0 release, which details the breaking changes introduced in v1.1.0.

Selecting fastOptJS or fullOptJS

sbt-web-scalajs looks up the scalaJSStage setting from the Scala.js projects to know whether to run fastOptJS or fullOptJS.

  • scalaJSStage setting is set to FastOptStage by default, which means sbt-web-scalajs runs fastOptJS by default.
  • scalaJSStage := FullOptStage can be set in a Scala.js project, so that sbt-web-scalajs runs fullOptJS for that project.
  • scalaJSStage in Global := FullOptStage sets FullOptStage for all the Scala.js projects from the build.

How it works

There are two plugins: WebScalaJS and ScalaJSWeb.

  • WebScalaJS is automatically added to your SbtWeb project.
  • ScalaJSWeb should be manually added to the Scala.js projects that are used by your SbtWeb project.
  • Scala.js projects are collected in the scalaJSProjects setting key of the SbtWeb project. The plugin does nothing if scalaJSProjects is not specified or is empty.
  • When compilation or testing takes place, then the WebScalaJS plugin runs all required tasks on scalaJSProjects projects, copies the output to sbt-web assets and takes care of Source Maps.

Settings and Tasks

Defined in WebScalaJS:

  • scalaJSProjects setting lists the Scala.js projects whose output are used by the server.

  • scalaJSPipeline task copies the JavaScript and Source Map files produced by Scala.js to the sbt-web assets. Scala files are also copied to be used for Source Maps.

    More precisely, scalaJSPipeline performs the following tasks for each project defined in the scalaJSProjects setting:

    • If Scala.js' scalaJSStage setting is equal to:

      • FastOptStage, then run packageJSDependencies and fastOptJS.
      • FullOptStage, then run packageJSDependencies, packageMinifiedJSDependencies and fullOptJS.

      The resulting JavaScript files are copied to the sbt-web assets, along with their corresponding source map files (.map) if they exist.

    • Read the ScalaJSWeb's sourceMappings setting from the project and its transitive dependencies. sourceMappings lists the directories containing Scala files to be used for Source Maps. Copy all Scala files found in these directories to the sbt-web assets.

Defined in ScalaJSWeb:

  • sourceMappings setting lists the directories containing Scala files to be used for Source Maps. The Scala files from the Scala.js project need to be copied and packaged, so that the server can serve these files to the browser when using Source Maps. sourceMappings is scoped under Compile/Test and fastOptJS/fullOptJS. Let's have a look at the value of Compile/fastOptJS/sourceMappings in SBT:
> project client
> show Compile/fastOptJS/sourceMappings
[info] * (<path>/client/src/main/scala, d09610e823cb5bgb1d53)

The hash d09610e823cb5bgb1d53 has been computed from the directory's canonical path using sbt.io.Hash.halfHashString(f.getCanonicalPath) and is used to configure the Scala.js' mapSourceURI scalac option. When generating Source Maps, Scala.js will replace the prefix path of each Scala file with its hash value. The hash uniquely identifies a file/directory and can be safely exposed to the users as the full file path is not disclosed.

Source Maps

The plugin copies the Scala files to the sbt-web assets, so that they can be served to the browser and used for Source Maps.

By default, Source Maps are enabled in both fastOptJS and fullOptJS. However, Source Maps can easily be disabled in fullOptJS by adding the following line to the Scala.js project's settings:

scalaJSLinkerConfig in (Compile, fullOptJS) ~= (_.withSourceMap(false))

When Source Maps are disabled, the .map files and the Scala files are not copied and do not exist in the sbt-web assets.

Note that Source Maps only get requested by the browser when the DevTools is open, so it does not hinder the performance of your website.

Scala.js continuous compilation

The plugin also watches files from the Scala.js projects. Redefine compile to trigger scalaJSPipeline when using compile, ~compile, ~run:

compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value

Publish a new version of the plugin

For Scala.js 1.x (no need to cross publish as Scala.js 1.x only supports SBT 0.13.x):

$ sbt publish

For Scala.js 0.6.x:

$ SCALAJS_VERSION=0.6.32 sbt ^publish
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].