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

How can I load a json file in the dojo application build profile?

我有以下 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.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。出了点问题。

如果您是 运行 NodeJS 的 Dojo 构建者,您可以通过 require.nodeRequire 访问它的 require。在构建配置文件中,您还可以访问一个名为 selfPath 的变量,它是您传递给构建器的配置文件的绝对目录名称(类似于节点模块中的 __dirname)。将这两件事放在一起并假设 ThirdPartyJsLibRootMap.json 是您的构建配置文件的兄弟:

var profile = (function () {
    var req = require.nodeRequire;
    var path = req('path');
    var versions = req(path.join(selfPath, 'ThirdPartyJsLibRootMap.json'));
    return {
        ...
    };
})();