Welcome to the Scala Commons Sbt Plugin documentation page!

Overview

Overview Preview | Edit

ScommonsPlugin

The main purpose of this sbt auto-plugin is to copy/extract resource files (css, png, jpeg) from project dependencies to the webpack folder during the fastOptJS/fullOptJS scalajs task, so they can be used later by the webpack task.

This is very similar to copying/extracting of *.js files, which is already provided by the ScalaJSBundlerPlugin.

Since this plugin is sbt auto-plugin, it will be automatically activated for all the projects that depend on ScalaJSBundlerPlugin.

It provides the following settings:

val scommonsResourcesFileFilter: SettingKey[FileFilter] = settingKey[FileFilter](
  "File filter of resources files, that should be automatically copied/extracted to the webpack directory"
)

val scommonsResourcesArtifacts: SettingKey[Seq[ModuleID]] = settingKey[Seq[ModuleID]](
  "List of artifacts (JARs) with resources, that should be automatically extracted to the webpack directory"
)

With default values:

scommonsResourcesFileFilter :=
  "*.css" ||
    "*.ico" ||
    "*.png" ||
    "*.jpg" ||
    "*.jpeg" ||
    "*.gif"

scommonsResourcesArtifacts := Seq(
  "org.scommons.client" % "scommons-client-ui" % "*"
)

You can extend/override the default values:

settings(
    scommonsResourcesFileFilter :=
        scommonsResourcesFileFilter.value || "*.svg",

    scommonsResourcesArtifacts ++= Seq(
      "your.org" % "your-dependency" % "*"
    )
)

WebpackAssetsPlugin

The main purpose of this sbt auto-plugin is to make the assets (css), produced by the webpack task, available as sbt-web assets.

This is very similar to the npmAssets task, which is already provided by the WebScalaJSBundlerPlugin.

Since this plugin is sbt auto-plugin, it will be automatically activated for all the projects that depend on WebScalaJSBundlerPlugin.

It provides the following task:

val webpackAssets: TaskKey[Seq[PathMapping]] = taskKey[Seq[PathMapping]](
  "Assets (resources that are not CommonJS modules) produced by Webpack"
)

It depends on the webpack task which in turn depends on scalajs task. Thus this task should be scoped by a scalajs task (fastOptJS or fullOptJS).

To use it for particular client project, add the following to your web-project (server) settings:

settings(
    webpackAssets in fastOptJS ++= WebpackAssets.ofProject(fastOptJS, clientProject) { build => (build / "styles").*** }.value,
    webpackAssets in fullOptJS ++= WebpackAssets.ofProject(fullOptJS, clientProject) { build => (build / "styles").*** }.value
)

(here, clientProject is your client sbt Project definition.)

Or for all specified scalaJSProjects:

settings(
    webpackAssets in fastOptJS ++= WebpackAssets.ofScalaJSProjects(fastOptJS) { build => (build / "styles").*** }.value,
    webpackAssets in fullOptJS ++= WebpackAssets.ofScalaJSProjects(fullOptJS) { build => (build / "styles").*** }.value
)