Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RequireJS Dependent Paths

Tags:

requirejs

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)?

like image 796
Ben Foster Avatar asked Jan 16 '13 15:01

Ben Foster


1 Answers

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.

like image 149
Gary Chang Avatar answered Oct 21 '22 22:10

Gary Chang