【问题标题】:Use coffeescripted-sbt to compile coffeescript in multi-project build在多项目构建中使用coffeescripted-sbt 编译coffeescript
【发布时间】:2013-06-21 18:15:27
【问题描述】:

我有一个多项目 sbt 构建,我想使用 https://github.com/softprops/coffeescripted-sbt 将我的咖啡脚本编译为 javascript,但它没有执行任务。

代码取自https://github.com/jeffmay/angular-play-multimodule-seed/tree/stackoverflow-17289043

使用 build.sbt

尽管不推荐,我还是将项目目录中的 build.sbt 文件与我的项目对象混合在一起,以测试此插件是否有效。

build.sbt:

seq(coffeeSettings: _*)

我跑的时候:

$ sbt
[info] Loading project definition from /Users/jeffmay/code/righttrack/project
[info] Set current project to root (in build file:/Users/jeffmay/code/righttrack/)
> coffee
[success] Total time: 0 s, completed Jun 24, 2013 11:40:37 PM
> show coffee
[info] ArrayBuffer()
[success] Total time: 0 s, completed Jun 24, 2013 11:40:52 PM
> project web
[info] Set current project to web (in build file:/Users/jeffmay/code/righttrack/)
[web] $ coffee
[error] Not a valid command: coffee
[error] No such setting/task
[error] coffee
[error]       ^
[web] $

ArrayBuffer() 是什么意思?这是无声的失败(coffeescript 返回最后一个表达式,否则将是 return;null?)

多项目设置

在某些情况下,我的构建是这样分解的......

project/plugins.sbt:

// SBT community plugin resolver
resolvers += Resolver.url("sbt-plugin-releases",
  new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)

// CoffeeScript compiler plugin
addSbtPlugin("me.lessis" % "coffeescripted-sbt" % "0.2.3")

project/Modules.scala(我的构建对象)中:

import sbt._

object Modules extends Build {

  lazy val root = RootModule.project

  lazy val api = ApiModule.project

  lazy val web = WebModule.project
}

project/WebModule.scala

object WebModule extends BaseModule {

  // ... libraries dependencies and stuff

  override def project = play.Project(moduleName, moduleVersion, libraries, file(location),
    moduleSettings ++
    Seq((resourceManaged in (Compile, CoffeeKeys.coffee)) <<= (crossTarget in Compile)(_ / "src" / "main" / "coffee"))
  )
}

我使用project/BaseModule.scala 来消除每个模块的公共元素的混乱,但它并没有做任何花哨的事情。

使用 Build.scala

我删除 build.sbt 的东西并通过 project/WebModule.scala 将其放入 Build.scala 并添加:

  override def project = play.Project(moduleName, moduleVersion, libraries, file(location),
    moduleSettings ++
    coffeeSettings ++  // With the settings moved from build.sbt
    Seq((resourceManaged in (Compile, CoffeeKeys.coffee)) <<= (crossTarget in Compile)(_ / "src" / "main" / "coffee"))
  )

那我试一试

$ sbt
[info] Loading project definition from /Users/jeffmay/code/righttrack/project
[info] Set current project to root (in build file:/Users/jeffmay/code/righttrack/)
> coffee
[error] Not a valid command: coffee
[error] No such setting/task
[error] coffee
[error]       ^
> project web
[info] Set current project to web (in build file:/Users/jeffmay/code/righttrack/)
[web] $ coffee
[success] Total time: 0 s, completed Jun 25, 2013 12:08:36 AM
[web] $ show coffee
[info] ArrayBuffer()
[success] Total time: 0 s, completed Jun 25, 2013 12:08:40 AM

运行 coffee 命令后我没有看到任何变化。任何想法是什么问题?

谢谢!

【问题讨论】:

    标签: coffeescript sbt


    【解决方案1】:

    更多详情请查看我与 softprops 的对话:https://github.com/softprops/coffeescripted-sbt/issues/17

    上面的代码存在三个问题和一个改进。

    1. 我没有将我的 Web 项目聚合到根项目中。

    2. 我没有设置在哪里可以找到咖啡脚本文件。

    3. Play使用“./app”作为sourceDirectory,所以当我添加看似“正确”的目录路径时

      sourceDirectory in (Compile, CoffeeKeys.coffee) <<= sourceDirectory { _ / "main" / "coffee" }
      

      它在“./app/src/main/coffee”中搜索,不存在

    我可以通过让编译器管理 ./public 目录来改进这个示例,这样它就可以将已编译的 javascript 源放到 Angular 种子项目推荐的 public/js 目录中。

    您可以在此处查看完整的种子项目示例:https://github.com/jeffmay/angular-play-multimodule-seed

    【讨论】:

      猜你喜欢
      • 2013-07-25
      • 2015-03-11
      • 2017-01-15
      • 1970-01-01
      • 1970-01-01
      • 2014-12-04
      • 2018-11-18
      • 2013-12-20
      • 2021-05-28
      相关资源
      最近更新 更多