5

我想将scala-jssbt-web一起使用,以便可以编译它以生成添加到资产管道(例如 gzip、digest)的 javascript 资产。我知道 lihaoyi 的工作台项目,但我认为这不会影响资产管道。这两个项目如何集成为 sbt-web 插件?

4

2 回答 2

3

Scala-js 从 Scala 文件生成 js 文件。sbt-web 文档将此称为源文件任务

结果看起来像这样:

val compileWithScalaJs = taskKey[Seq[File]]("Compiles with Scala js")

compileWithScalaJs := {
  // call the correct compilation function / task on the Scala.js project
  // copy the resulting javascript files to webTarget.value / "scalajs-plugin"
  // return a list of those files
}

sourceGenerators in Assets <+= compileWithScalaJs

编辑

创建插件需要更多的工作。Scala.js 还不是一个AutoPlugin.,所以你可能有一些依赖问题。

第一部分是将 Scala.js 库作为依赖项添加到插件中。您可以通过使用如下代码来做到这一点:

libraryDependencies += Defaults.sbtPluginExtra(
  "org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % "0.5.5", 
  (sbtBinaryVersion in update).value, 
  (scalaBinaryVersion in update).value
)

你的插件看起来像这样:

object MyScalaJsPlugin extends AutoPlugin {
  /* 
    Other settings like autoImport and requires (for the sbt web dependency), 
    see the link above for more information
  */

  def projectSettings = scalaJSSettings ++ Seq(
    // here you add the sourceGenerators in Assets implementation
    // these settings are scoped to the project, which allows you access 
    // to directories in the project as well
  )
}

然后在使用此插件的项目中,您可以执行以下操作:

lazy val root = project.in( file(".") ).enablePlugins(MyScalaJsPlugin)
于 2014-10-23T06:45:50.880 回答
1

看看sbt-play-scalajs。它是一个额外的 sbt 插件,有助于与 Play / sbt-web 集成。

您的构建文件将如下所示(从 README 复制):

import sbt.Project.projectToRef

lazy val jsProjects = Seq(js)

lazy val jvm = project.settings(
  scalaJSProjects := jsProjects,
  pipelineStages := Seq(scalaJSProd)).
  enablePlugins(PlayScala).
  aggregate(jsProjects.map(projectToRef): _*)

lazy val js = project.enablePlugins(ScalaJSPlugin, ScalaJSPlay)
于 2015-04-20T21:54:45.017 回答