如何在dojo应用程序构建配置文件中加载json文件?

时间:2015-04-02 19:09:53

标签: javascript dojo

我有以下dojo构建配置文件:

var profile = (function () {
    return {
        basePath: "./Scripts",
        releaseDir: "./bin",
        releaseName: "",
        action: "release",
        mini: true,
        layerOptimize: "closure",
        optimize: "closure",
        cssOptimize: "comments",
        localeList: false,
        packages: [
            {
                name: "dojo",
                location: "l:/dojo-debug/1.10.4/dojo"
            },
            {
                name: "dijit",
                location: "l:/dojo-debug/1.10.4/dijit"
            },
            {
                name: "dojox",
                location: "l:/dojo-debug/1.10.4/dojox"
            },
            ...
        ],
        layers: ...
    };
})();

现在,我需要从一些json文件中读取值,所以我正在寻找这样的东西:

var profile = (function () {
    var versions = SomeHowReadTheContentsOf("ThirdPartyJsLibRootMap.json");
    return {
        basePath: "./Scripts",
        releaseDir: "./bin",
        releaseName: "",
        action: "release",
        mini: true,
        layerOptimize: "closure",
        optimize: "closure",
        cssOptimize: "comments",
        localeList: false,
        packages: [
            {
                name: "dojo",
                location: "l:/dojo-debug/" + versions["dojo-debug"] + "/dojo"
            },
            {
                name: "dijit",
                location: "l:/dojo-debug/" + versions["dojo-debug"] + "/dijit"
            },
            {
                name: "dojox",
                location: "l:/dojo-debug/" + versions["dojo-debug"] + "/dojox"
            }
            ...
        ],
        layers: ...
    };
})();

对于我的生活,我没有找到办法。

有什么想法吗?

修改

我的命令行是:node L:\dojo-debug\1.10.4\dojo\dojo.js load=build --profile .\package.profile.js

EDIT2

我添加了require所有属性的控制台日志,结果如下:

has = undefined
isXdUrl = undefined
initSyncLoader = undefined
eval = undefined
signal = undefined
on = undefined
map = undefined
rawConfig = undefined
legacyMode = undefined
async = undefined
waitms = undefined
baseUrl = undefined
idle = undefined
toAbsMid = undefined
toUrl = undefined
log = undefined
trace = undefined
injectUrl = undefined
getText = undefined
nodeRequire = undefined
uid = undefined
cache = undefined
packs = undefined
paths = undefined
aliases = undefined
modules = undefined
execQ = undefined
defQ = undefined
waiting = undefined
mapProgs = undefined
pathsMapProg = undefined
listenerQueues = undefined
computeMapProg = undefined
computeAliases = undefined
runMapProg = undefined
compactPath = undefined
getModuleInfo = undefined
boot = undefined
scopeify = undefined

所以nodeRequire就在那里,但它的值是undefined。出了点问题。

1 个答案:

答案 0 :(得分:1)

如果您正在使用NodeJS运行Dojo构建器,则可以通过require访问其require.nodeRequire。在构建配置文件中,您还可以访问名为selfPath的变量,该变量是您传递给构建器的配置文件的绝对目录名(它与__dirname中的ThirdPartyJsLibRootMap.json类似。节点模块)。将这两件事放在一起并假设var profile = (function () { var req = require.nodeRequire; var path = req('path'); var versions = req(path.join(selfPath, 'ThirdPartyJsLibRootMap.json')); return { ... }; })(); 是您的构建配置文件的兄弟:

{{1}}