play フレームワークなしで sbt-web プラグインを使用し、代わりに xsbt-web-plugin を使用して webapp を構築しようとしています。
sbt-web プラグインがアセット パイプラインの処理で正しく動作するようになり、有効な webjar 出力 (packageBin 経由) と標準の "web/public/main" 出力 (アセット経由) を作成するようになりました。
これとは別に、私は xsbt-web-plugin を使用して webapp を開発し、その webapp を SBT 内から (container:start 経由で) 提供しています。webapp プロジェクトは、mavenCentral から webjar の依存関係を使用し、それらのリソースを問題なく参照できます。
私が把握できていないのは、xsbt-web-plugin を取得して、sbt-web パイプラインから出てくるアセットを Web アプリケーションに含める方法です。私にできる最善のことは、それらを CLASSPATH に入れることです。(私が理解していることから、これらのアセットを CLASSPATH から提供する「アセット コントローラー」があるため、これらのアセットを Web アプリケーションで静的アセットとして使用できるようにする必要がないため、プレイに必要なのはこれだけです)。
私がやろうとしていることを示す公開 GitHub リポジトリ ( https://github.com/MartinSnyder/serving-sbt-web-output ) を作成しました。
私の plugins.sbt は次のとおりです。
resolvers += Resolver.typesafeRepo("releases")
addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.1.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.6")
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "1.0.0")
私のbuild.sbtは次のとおりです。
name := "Example project serving sbt-web output from within SBT"
organization in ThisBuild := "com.martinsnyder"
version in ThisBuild := "0.0.1"
scalaVersion in ThisBuild := "2.11.6"
lazy val example_webjar =
project
.in(file("example_webjar"))
.settings(libraryDependencies ++= Seq("org.webjars" % "requirejs" % "2.1.16"))
.enablePlugins(SbtWeb)
lazy val example_webapp =
project
.in(file("example_webapp"))
.dependsOn(example_webjar)
.settings(libraryDependencies ++= Seq(
"javax.servlet" % "servlet-api" % "2.5" % "provided",
"org.eclipse.jetty" % "jetty-webapp" % "9.3.0.M2" % "container",
"org.eclipse.jetty" % "jetty-plus" % "9.3.0.M2" % "container",
"commons-logging" % "commons-logging" % "1.2" % "container"
))
.enablePlugins(SbtWeb)
.settings(jetty(): _*)
webapp の HTML ファイルは次のとおりです。
<html>
<head>
<title>Example</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" type="text/css" href="lib/example_webjar/css/main.css">
<link rel="stylesheet" type="text/css" href="webjar/example_webjar/0.0.1/css/main.css">
<script src="webjars/requirejs/2.1.16/require.js"></script>
</head>
<body>
<div class="red">Red</div>
<div class="green">Green</div>
</body>
</html>
現在のところ、requirejs はビルド前の webjar から来ているため、正常に提供されています。3 つのタグはすべて異なっており、sbt-web からのアセット出力を参照しようとして失敗しています。
私が達成しようとしている最良のシナリオは、xsbt-web-plugin webapp 出力 (target/webapp/) に含まれる sbt-web プラグイン出力 (target/web/public/main/)を取得することです。プロジェクトの依存関係に webjar としてアクセスできる xsbt-web-plugin で解決します。