How can I tell the contents of a webjar?

2019-09-06 09:36发布

Let's say I want to 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"
)

How do I tell which assets are available in the react webjar?

If I try to access simply "react.js", 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"))'>

2条回答
叛逆
2楼-- · 2019-09-06 10:19

The easiest way to see the contents of WebJars is on http://www.webjars.org

You can see that there are in fact two instances of react.js in the WebJar. So if you want to use the locator you need to be more specific about the path. But in this case I'd recommend you use the Play asset pipeline that auto-extracts WebJar contents. Docs on that: https://www.playframework.com/documentation/2.3.x/Assets

So your code would be:

<script type='text/javascript' src='@routes.Assets.at("lib/react/react.js")'>
查看更多
Luminary・发光体
3楼-- · 2019-09-06 10:24

In my project, it turned out that the react webjar was installed here (I wonder where it's documented though):

target/web/web-modules/main/webjars/lib/react/
查看更多
登录 后发表回答