5

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

4

2 回答 2

5

不,这是不可能的。

引用 James Burke 对这张票中类似问题的回答:

路径不是附加的——路径条目的属性名称是模块 ID,值是不是从其他值计算的路径。

我认为您确实必须单独定义每个 js 文件路径,我想不出更好的方法来做到这一点。

于 2013-02-13T06:16:16.827 回答
0

这应该没问题,但是require(["libs/jquery"]应该更改为,require(["jquery"]因为您已经在配置中定义了该别名。

于 2013-01-16T15:40:20.730 回答