如何阻止xsbt重新加载webapp上的资源变化

时间:2014-09-16 12:55:40

标签: sbt lift xsbt-web-plugin

我们正在使用sbtxsbt-web-plugin来开发我们的liftweb应用。在我们的项目构建中,我们有几个子项目,我们使用dependencies的{​​{1}}来共享所有子项目之间的一些东西。

Project

为了简化开发,我们使用object ProjectBuild extends Build { //... lazy val standalone = Project( id = "standalone", base = file("standalone"), settings = Seq(...), dependencies = Seq(core) // please notice this ) lazy val core = Project( id = "core", base = file("core"), settings = Seq(...) } // ... } 命令自动重新编译已更改的文件。

我们决定从共享的'project standalone' '~;container:start; container:reload /'项目中提供一些公共资产。电梯可以很好地工作。但是我们在将文件添加到core文件夹时遇到的问题是,对任何javascript或css文件的任何更改都会导致应用程序重新启动jetty。这很烦人,因为这样的重新加载会占用大量资源。

所以我开始调查如何防止这种情况发生,甚至发现有人提到core/src/main/resources/toserve sbt任务扫描已更改的文件。

但是,将此代码添加为watchSources修改(watchSources打印所有文件的事件)并不会阻止每次更改位于println {{1}的资产时重新加载webapp }文件夹。

core

我也尝试将resources添加到lazy val core = Project( id = "core", base = file("core"), settings = Seq( // ... // here I added some tuning of watchSources watchSources ~= { (ws: Seq[File]) => ws filterNot { path => println(path.getAbsolutePath) path.getAbsolutePath.endsWith(".js") } } ) excludeFilter,但没有运气。

我不是专家,这样的设置修改对我来说更像是一种魔力(而不是通常的代码)。此类调整似乎也被文档发现=( 任何人都可以帮我阻止sbt重新加载每个资产文件更改的webapp?

非常感谢!

2 个答案:

答案 0 :(得分:0)

您使用watchSources走在正确的轨道上,但您还需要排除资源目录:

watchSources ~= { (ws: Seq[File]) =>
  ws filterNot { path =>
    path.getName.endsWith(".js") || path.getName == ("resources")
  }
}

答案 1 :(得分:0)

您可以切换使用"资源"文件夹使用" webapp"夹?这也将使您免于重启。这是Lift的演示项目(使用" webapp"):

https://github.com/lift/lift_26_sbt/

例如,"基本"模板:

https://github.com/lift/lift_26_sbt/tree/master/scala_211/lift_basic/src/main/webapp