2

I use the webjar react-0.12.2 in my Play Framework 2.3 project, and I've depended on it like so:

libraryDependencies ++= Seq(
  "org.webjars" %% "webjars-play" % "2.3.0-2",
  "org.webjars" % "react" % "0.12.2"
)

If I try to access 'react.js' though, like in the following example, I get an error due to there being multiple matches for react.js:

<script type='text/javascript' src='@routes.WebJarAssets.at(WebJarAssets.locate("react.js"))'>

The error:

MultipleMatchesException: Multiple matches found for react.js. Please provide a more specific path, for example by including a version number.

I've found that accessing 'react.min.js' instead works, so there's a problem with the 'react.js' path. But why is it going wrong, is there a bug?

4

1 回答 1

5

实际上react.js在 WebJar 中有两个实例。因此,如果您想使用定位器,您需要更具体地了解路径。在webjars-play版本之前2.3.0-3,没有单一的方法调用方式可以执行此操作,因此您可以执行以下操作之一:

使用 Play 2.3 的资产管道并通过提取目录访问文件:

<script type='text/javascript' src='@routes.Assets.at("lib/react/react.js")'>

或者您可以创建一个辅助方法,例如:

def fullPath(webjar: String, path: String): String = {
  val version = webJarAssetLocator.getWebJars.get(webjar)
  s"$webjar/$version/$path"
}

这将被用作:

<script type='text/javascript' src='@routes.WebJarAssets.at(fullPath("react", "react.js"))'>

或者,如果您升级到webjars-play版本2.3.0-3,那么您可以使用 now 内置WebJarAssets.fullPath方法:

<script type='text/javascript' src='@routes.WebJarAssets.at(WebJarAssets.fullPath("react", "react.js"))'>
于 2015-02-06T03:49:53.460 回答