Ben Foster
Ben Foster

Reputation: 34830

RequireJS Dependent Paths

I've just started using RequireJS. I'm setting up a few path aliases to save me from having to specify the version number on my dependencies but it seems I can't combine a path alias with a directory alias. For example:

require.config({
    baseUrl: "/js/app", // by default load any module IDs from js/app

    paths: {
        "libs": "/some/path/to/libs",
        "jquery": "libs/jquery-1.9.0" // loads from /some/path/to/libs/jquery-1.9.0.js
    }
});

require(["jquery"], function ($) {
    $("#foo").html("bar");
});

RequireJS attempts to load jquery from /js/app/libs/jquery-1.9.0.js

Is this possible or would I need to define each js file path separately (if I didn't want to remove the version number)?

Upvotes: 5

Views: 879

Answers (2)

Gary Chang
Gary Chang

Reputation: 1042

No, this isn't possible.

To quote James Burke's answer to a similar question in this ticket:

Paths are not additive -- the property name for a path entry is a module ID and the value is a path that is not computed from other values.

I think you do have to define each js file path separately, I can't think of a better way to do it.

Upvotes: 5

Nick Jonas
Nick Jonas

Reputation: 1237

This should be fine however require(["libs/jquery"] should be changed to require(["jquery"] since you've defined that alias in your config.

Upvotes: 0

Related Questions