【问题标题】:How to stop xsbt from reloading webapp on resources change如何阻止 xsbt 在资源更改时重新加载 webapp
【发布时间】:2014-09-30 01:09:17
【问题描述】:

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

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 项目的一些常见资产。这适用于电梯。但是当我们将文件添加到core/src/main/resources/toserve 文件夹时,我们面临的是对任何 javascript 或 css 文件的任何更改都会导致应用程序重新启动码头。这很烦人,因为这种重新加载会占用大量资源。

所以我开始研究如何防止这种情况,甚至发现有人提到watchSources sbt 扫描更改文件的任务。

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

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 添加到unmanagedSorcesunmanagedResorces,但没有成功。

我不是 sbt 专家,对设置的这种修改对我来说更像是一种魔法(而不是普通的代码)。文档似乎也发现了这种调整=( 谁能帮我防止 sbt 在每次资产文件更改时重新加载 webapp?

非常感谢!

【问题讨论】:

    标签: sbt lift xsbt-web-plugin


    【解决方案1】:

    使用watchSources 是正确的,但您还需要排除 resources 目录本身:

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

    【讨论】:

    • 嗨!感谢您的建议,但这无济于事=(如果我在 core 中编辑并保存一些 js 文件,Liftweb 应用程序仍会重新加载。
    • .js 文件具体在哪里?它在 core/src/main/resources 中吗?
    • 文件存储在/core/src/main/resources/toserve/core/js/,但从/core/src/main/resources/ 编辑的任何文件都会导致相同的行为。
    • 您可能还需要在根项目中重用上面的watchSources 过滤器。当您仅在 core 子项目上执行触发执行时,您是否看到同样的问题?
    • core 本身没有容器配置。所以这样做'project core' '~;container:start; container:reload /' 不起作用(No such setting/task container:start)。我尝试在ProjectBuild 中将相同的watchSources 添加到standalone 应用程序配置,但没有运气(编辑核心资源文件夹中的任何文件仍会导致应用程序重新加载)。
    【解决方案2】:

    你能从使用“resources”文件夹切换到使用“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

    【讨论】:

    • 顺便说一句,很抱歉回答迟了。官方支持频道是邮件列表,虽然我个人也尝试观看 stackoverflow。 (我的 RSS 客户端坏了 2 周)。
    • 这似乎没有任何子项目使用另一个子项目作为依赖项的项目。在我的示例中,无法使用 core 内部的 webapp 内容。
    猜你喜欢
    • 2013-03-06
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    • 1970-01-01
    相关资源
    最近更新 更多