0

我有一个多项目 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()意思?这是一个无声的失败(咖啡脚本返回最后一个表达式,否则它会是 a 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"))
  )
}

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

使用 Build.scala

我删除了build.sbt这些东西,并Build.scala通过project/WebModule.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

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

谢谢!

4

1 回答 1

0

有关详细信息,请参阅我与 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 源代码放到public/jsAngular 种子项目的推荐目录中。

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

于 2013-06-26T05:19:15.453 回答