需要

2012-06-28 30 views
0

我使用RequireJS 2.0.2需要

我在作爲切入點文件下面的js路徑不被認可。

require({ 

    "packages" : ['bi/charts'], 
    baseurl  : '/js/', 
    paths  : { 
     handlebars : "lib/handlebars-1.0.0.beta.6", 
     jquery  : "lib/jquery-1.7.2.min", 
     underscore : "lib/underscore-1.3.3.min", 
     modernizr : "lib/modernizr-custom.2.5.3.min", 
     BI   : "bi/BIf" 
    } 
}); 

但它只能識別 'jQuery的',沒有其他路徑的,它回來,出現以下錯誤:

NetworkError: 404 Not Found - [link]http://localhost:62033/js/handlebars.js" 
handlebars.js 
Script error http://requirejs.org/docs/errors.html#scripterror 
[Break On This Error] 

var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id); 

....想法?

非常感謝。

回答

2

在需要之前,您可能需要調用配置。另外請注意向路徑添加斜槓。用途:

"handlebars" : "/lib/handlebars" 

"handlebars" : "lib/handlebars" 


    require.config({ 
    baseUrl: "/js/", 
    paths: { 
     "handlebars": "/lib/handlebars" 
    }, 
    }); 
    require(["handlebars"], 
    function(handlebars, myModule) { 
    } 
); 

參見Config Paths

+0

想通了。因爲我正在構造頁面中的多個require調用,包含require.config調用的main.js文件在require()調用首先執行時沒有機會加載。必須在頁面中放置require.config調用,而不是從main.js調用。 – quinton

+5

然後自己創建一個答案,並將其標記爲已解決,以便它看起來應答。 :) – pdjota