Thanks,
Marius
On Fri, Apr 3, 2015 at 7:38 PM, Eduard Moraru <enygma2002(a)gmail.com> wrote:
Hi,
Currently, the webjars URL mapping is the following:
http://localhost:8080/xwiki/bin/webjars/resources/path?value=
<id>%2F<version>%2F<filePath>
Example:
$services.webjars.url('codemirror', 'lib/codemirror.js')
returns
http://localhost:8080/xwiki/bin/webjars/resources/path?value=codemirror%2F5…
The problem with this is that require modules that use relative paths for
their dependencies are broken because of the URL mapping we use, more
specifically by the "?" character inside the URL we use.
A concrete example is the CodeMirror webjar that defines its own modules
which express their dependencies relatively: "../../lib/codemirror"
Here we have a problem, since if we directly depend on
"$services.webjars.url('codemirror', 'mode/css/css.js')", the
module will
fail to find its relatively defined dependency.
One approach would be to define paths, so that requirejs can work its magic:
require.config({
paths: {
cm : "
http://localhost:8080/xwiki/bin/webjars/resources/path?value=codemirror%2F5…
"
}
});
require(["cm/lib/codemirror", "cm/mode/css/css"], function
(CodeMirror) {
console.log(CodeMirror);
});
This properly finds "/lib/codemirror.js" and "mode/css/css.js" that
we
explicitly request, however, the internal dependency of css.js fails to be
found at the resolved URL "
http://localhost:8080/xwiki/bin/webjars/resources/path?value=codemirror%2F5…
".
Requirejs does not add the ".js" extension to the resolved path because the
resolved path contains a "?" character so it is considered an absolute URL,
not a relative path.
The proposal is to stop using this URL mapping, since it is awkward to have
paths in parameters and, instead, use a more intuitive one that is both
good for clients and for requirejs.
The proposed mapping/scheme is:
http://localhost:8080/xwiki/bin/webjars/<id>/<version>/<file…
Any additional parameters that we might need for the webjars action would
be appended at the end. There is currently 1 case that I know of, which is
"evaluate=true|false".
Without this change, I can not find any solution to using a webjar such as
CodeMirror that uses relative defined modules.
Thanks,
Eduard
P.S.: Any additional advice on using requirejs to circumvent this
limitation is most than welcomed.
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs