0

是否可以将模块传递给require.config?我有一个在 require.config 之前在 DOM 中创建的模块,其中包含服务器端配置数据,我希望能够访问我的 require.config 文件中的那个。这是我正在尝试做的一个例子。

    define("config", 
    [],
    function() {
        var Config = {};   
        Config.locale = '{$locale}';
        Config.version = '{$version}';
        return Config;
    });

然后我希望能够将 Config 模块传递给 require.config 。

require.config({

  paths: {
    link1: "//url/" + Config.version + "/data.js",
    link2: "//url/" + Config.version + "/data.js",
    link3: "//url/" + Config.version + "/data.js"
},

与往常一样,非常感谢任何帮助!

4

1 回答 1

0

Have you tried your method? Although I haven't, I'm pretty sure config is not treated as a module.

You could take advantage of defining require as an object before the library is loaded.

<script>
    var require = (function(){

        // Do your setup stuff here

        // Now return the config object
        return {
            baseUrl: 'test/path/'
            paths: {
                // etc
            }
        }

    })()
</script>
<script src="require.js"></script>
于 2012-11-01T10:07:31.707 回答