आप ग्राहक की में precompile कर सकते हैं ब्राउज़र, थॉमस Bartelmess के रूप में कहा।
तुम भी precompile NodeJS के माध्यम से हैंडल (मेरी बहुत ही Jakefile से लिया गया) का उपयोग कर सकते हैं:
var Handlebars = require('handlebars');
precompile = (function() {
//Lovingly extracted from Ember's sources.
var objectCreate = Object.create || function (parent) {
function F() {}
F.prototype = parent;
return new F();
},
Compiler = function() {},
JavaScriptCompiler = function() {};
Compiler.prototype = objectCreate(Handlebars.Compiler.prototype);
Compiler.prototype.compiler = Compiler;
JavaScriptCompiler.prototype = objectCreate(Handlebars.JavaScriptCompiler.prototype);
JavaScriptCompiler.prototype.compiler = JavaScriptCompiler;
JavaScriptCompiler.prototype.namespace = "Ember.Handlebars";
JavaScriptCompiler.prototype.initializeBuffer = function() {
return "''";
};
JavaScriptCompiler.prototype.appendToBuffer = function (string) {
return "data.buffer.push(" + string + ");";
};
Compiler.prototype.mustache = function (mustache) {
if (mustache.params.length || mustache.hash) {
return Handlebars.Compiler.prototype.mustache.call(this, mustache);
} else {
var id = new Handlebars.AST.IdNode(['_triageMustache']);
if (!mustache.escaped) {
mustache.hash = mustache.hash || new Handlebars.AST.HashNode([]);
mustache.hash.pairs.push(["unescaped", new Handlebars.AST.StringNode("true")]);
}
mustache = new Handlebars.AST.MustacheNode([id].concat([mustache.id]), mustache.hash, !mustache.escaped);
return Handlebars.Compiler.prototype.mustache.call(this, mustache);
}
};
return function precompile(string) {
var ast = Handlebars.parse(string);
var options = {
knownHelpers : {
action : true,
unbound : true,
bindAttr : true,
template : true,
view : true,
_triageMustache : true
},
data : true,
stringParams : true
};
var environment = new Compiler().compile(ast, options);
return new JavaScriptCompiler().compile(environment, options, undefined, true);
};
}());
strPrecompiledTemplate = item.handlebarsTemplateFolders.map(function (dir) {
console.info("\tProcessing " + dir);
return readdirRecursiveSync(dir).map(function (file) {
console.info("\t\t" + file);
var content = fs.readFileSync(file, 'utf-8');
content = Handlebars.precompile(content);
file = file.replace(/\.[^\.]+$/, '').replace(/^src\//g, '').substr(dir.length).replace(/^\/+/, '');
// Pay attention: The wrap in Ember.Handlebars.template() is important!
return "Ember.TEMPLATES['"+file+"'] = Ember.Handlebars.template("+content+");";
}).join("\r\n");
}).join("\r\n");
आप 'उपयोग कर रहे हैं gulp' मैं हाल ही में एक पैकेज प्रकाशित बुलाया NPM को [घूंट-एंबर-टेम्पलेट्स] (https://www.npmjs.org/package/gulp-ember -टेम्प्लेट्स) जो आपके हैंडलबार्स टेम्पलेट्स को जावास्क्रिप्ट में संकलित करेगा और फिर आप उन्हें एक फ़ाइल में – Stuart
संभावित डुप्लिकेट में शामिल कर सकते हैं [नोडजेस के साथ एम्बरजे हैंडलबार टेम्पलेट्स को प्रीकंपाइल करने का आसान तरीका?] (http://stackoverflow.com/questions/9171583/ आसान-से-प्री-कॉम्पैम्प-एम्बरजेस-हैंडलबार-टेम्पलेट्स-साथ-नोडजेस) – givanse