2013-10-25 4 views
1

브런치와 핸들을 사용하여 dev 환경을 설정하려고합니다. handlebars-brunch 패키지는 내 vendor.js 파일에 포함 된 node_moduleshandlebars.runtime.js에 저장됩니다. 나는이 템플릿을 정의했습니다 :브런치 - Handlebars.templates가 정의되지 않았습니다.

hello.template :

templates: 
     defaultExtension: 'handlebars' 
     joinTo: 'app.js' 

그리고 그것이 작동하는 증거로

, 내가 볼 수

<p>Hello {{name}}</p>

그리고이 config.coffee 내에이 줄을 추가 내 app.js에 다음 줄이 있습니다.

;var __templateData = Handlebars.template(function Handlebars,depth0,helpers,partials,data) { 
this.compilerInfo = [4,'>= 1.0.0']; 

helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; 
var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression; 


buffer += "<p>Hello "; 
if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); } 
else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } 
buffer += escapeExpression(stack1) 
    + "</p>\r\n\r\n"; 
return buffer; 
}); 
if (typeof define === 'function' && define.amd) { 
    define([], function() { 
     return __templateData; 
    }); 
} else if (typeof module === 'object' && module && module.exports) { 
    module.exports = __templateData; 
} else { 
    __templateData; 
} 

하지만이 같은 Handlebars.templates.hello 호출 할 때 :

var tpl = Handlebars.templates.hello; 
var html = tpl ({ name: "ok" }); 
console.log (tpl); 

을이 오류를 얻을 : Cannot read property 'hello' of undefined합니다. 따라서 Handlebars는 정의되었지만 템플릿은 아닙니다.

[...] 
if (typeof define === 'function' && define.amd) { 
    define([], function() { 
     return __templateData; 
    }); 
} else if (typeof module === 'object' && module && module.exports) { 
    module.exports = __templateData; 
} else { 
    __templateData; 
} 

;(function ($, document, window) { 
    var tpl = Handlebars.templates.hello; 
    var html = tpl ({ name: "ok" }); 
    console.log (tpl); 
} (jQuery, document, window)); 

모든 아이디어/제안 : 내 주요 기능은 다음과 같이 다른 모든 뒤에 위치로 내 종속성 포함이 너무 잘 보인다?

답변

1

브런치는 모듈을 사용합니다. 전역 변수 등을 지정하지 않습니다. 파일 네임 스페이스 내 자바 스크립트 내가 둥지로

+0

app/name.js을했다 경우

require('name') 

, 내가 config.coffee에서 모듈 비활성화 (: 래퍼 : 잘못된 정의 : '모듈을 FALSE'). 템플릿을 사용하기 위해 모듈을 사용해야합니까? 이렇게 :'var helloTemplate = require ('hello'); html = helloTemplate ({name : 'ok'})'? – Simon

+0

네, 이렇게. 모듈이 필요합니다. 브런치 플러그인에는 전역 변수에 대한 지원이 없지만 실제로 필요한 경우 풀 요청에 대해 공개되어 있습니다. –

+0

아니, 할 수있는 한 괜찮아. :) 고마워! – Simon

관련 문제