2013-01-07 35 views
0

我嘗試優化使用客戶端玉模板的客戶端腳本時遇到問題。最初,我遇到了如Require.js + Backbone optimization中所述的錯誤,但隨後我從路徑配置中刪除了「文本」模塊,將其添加到本地可用的排除項和text.js中。這樣做後,我得到一個錯誤,其中optmizer嘗試解析傳遞給文本模塊的參數。優化器和把手客戶端玉模板

這裏是我的客戶端模板:

define([ 
'Handlebars', 
'text!/templates/product/something.jade' 
], function(Handlebars, txtSomething) { 
    var template = Handlebars.template, 
     templates = Handlebars.templates = Handlebars.templates || {}; 

    templates['something'] = Handlebars.compile(txtSomething); 
}); 

然後優化配置:

({ 
    baseUrl: ".", 
    name: "product", 
    out: "product.js", 
    paths: { 
    Handlebars: "empty:" 
    }, 
    exclude: ["text"] 
}) 

和錯誤,我得到:

Error: ENOENT, no such file or directory 'C:\templates\product\something.jade' 
In module tree: 
    product 
    modules/something 
     templates/something 
     text 

如何解決任何意見問題?

+0

關於此實現的註釋 - 它位於express.js應用程序中,該應用程序的模板路徑配置如下: app.get(「/ templates/product /:template」,函數(req,res)res.render(「product/templates /」+ req.params.template,{req:req} }) – Brett

+0

你的app.js(express)中有view配置嗎? .set('views',__dirname +'/ views'); app.set('view engine','jade'); – asgoth

+0

是的,這是在app.js.中設置的,但是,當我運行優化器時,它如果我將視圖的引用更改爲'text!../../../../ views/product/something.jade',那麼優化器將運行時沒有錯誤。但是這打破了當地的開發ELopment(IDE)配置,我需要使用基於URI的引用而不是基於文件的引用。 – Brett

回答

0

我在運行優化之前預編譯句柄模板。刪除文本引用