On Aug 1, 2013, at 8:53 AM, Marius Dumitru Florea <mariusdumitru.florea(a)xwiki.com>
wrote:
+1 but we need an API to create the webjar URLs.
Yes, I had thought of this too. It would be nice to not have to add the
"/xwiki/webjar" prefix but more importantly it'll work even if you change
the servlet context.
Thanks
-Vincent
Thanks,
Marius
On Wed, Jul 31, 2013 at 5:18 PM, Vincent Massol <vincent(a)massol.net> wrote:
> Hi devs,
>
> I'd like to make it easy in XWiki to use javascript frameworks required by
extensions.
>
> I've found the webjars project (
http://webjars.org) which packages javascript
frameworks in JAR files available in Maven Central.
>
> They work out of the box if you drop them in WEB-INF/lib in a Servlet 3.0 container
(like Jetty 7). It works because the 3.0 spec says that any files located in
META-INF/resources/<path> will be made available by the servlet container as static
resources (accessible as <path>).
>
> However the servlet 3.0 specs doesn't support adding those JAR dynamically
outside of WEB-INF/lib so it doesn't work with our extension mechanism.
>
> Thus I'm proposing the following (which I have tested to work):
>
> * Add a new WebJarFilter filter to web.xml
> * The URL to access, for ex, angular.js packaged in the
http://repo2.maven.org/maven2/org/webjars/angularjs/1.1.5-1/angularjs-1.1.5… jar
would be: /xwiki/webjar/angularjs/1.1.5/angular.js
>
> This allows for example to have a dep on:
>
> <dependency>
> <groupId>org.webjars</groupId>
> <artifactId>angularjs</artifactId>
> <version>1.1.5-1</version>
> <scope>runtime</scope>
> </dependency>
>
> Then in a JSX object:
>
> require(["/xwiki/webjar/angularjs/1.1.5/angular.js"], function() {
> …
> });
>
> WDYT?
>
> Thanks
> -Vincent