加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala-js如何与sbt-web集成?

发布时间:2020-12-16 18:39:06 所属栏目:安全 来源:网络整理
导读:我希望 scala-js与 sbt-web一起使用,以便可以编译它以生成添加到资产管道的javascript资产(例如gzip,digest).我知道lihaoyi的工作台项目,但我不认为这会影响资产管道.如何将这两个项目集成为sbt-web插件? 解决方法 Scala-js从Scala文件生成js文件. sbt-web
我希望 scala-js与 sbt-web一起使用,以便可以编译它以生成添加到资产管道的javascript资产(例如gzip,digest).我知道lihaoyi的工作台项目,但我不认为这会影响资产管道.如何将这两个项目集成为sbt-web插件?

解决方法

Scala-js从Scala文件生成js文件. sbt-web文档称之为 Source file task.

结果看起来像这样:

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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读