Answer the question
In order to leave comments, you need to log in
Backbone requirejs Templates after node + r.js optimization?
Hello. I continue my torment with the development of a small front-end application.
Now I ran into this problem:
Backbone + requirejs + plugin for templating !text
There are a lot of templates so I don't want to include them in the page !text handles it very well.
But here I decided to try to code all this with the help of node and r.js, after optimization, the templates also merge into one file.
Having rummaged in the settings, I found the necessary parameter that allows you not to include text dependencies:
//Inlines the text for any text! dependencies, to avoid the separate
//async XMLHttpRequest calls to load those dependencies.
inlineText: true,
{
baseUrl: "f/app",
appDir: "..",
dir: "dist",
modules: [
{
name: "catalog"
}
],
stubModules: ['text'],
optimizeAllPluginResources: false,
inlineText: false,
paths: {
app: '../libs',
jquery: 'empty:',
underscore: 'empty:',
backbone: 'empty:',
marionette: 'empty:',
JSON: 'empty:',
// Plugins
text: '../libs/rjs-text',
},
exclude: ["jquery","underscore","backbone","marionette", 'JSON', 'text']
}
Answer the question
In order to leave comments, you need to log in
github.com/gruntjs/grunt-contrib-jst
var JST = window.JST = window.JST || {};
var fetchTemplate = function (name) {
var path = 'app/templates/' + name + '.html';
if (!JST[path]) {
$.ajax({
url: path,
async: false
})
.then(function (contents) {
JST[path] = _.template(contents);
});
}
return JST[path];
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question