Frage

I want to precompile underscore templates and include them in my app.js target file of grunt-browserify.

I know that there is the option transform:hsbfy for handlebars templates, but how can I do the same with underscore templates?

I tried using node-underscorify without success

War es hilfreich?

Lösung

You should use the option transform: ['node-underscorify'].

browserify: {
    app: {
        files: {
            'dist/js/app.js': ['app/main.js']
        },
        options: {
            transform: ['node-underscorify'],
            debug: true,
            external: ['jquery', 'underscore', 'backbone', 'backbone.marionette']
        }
    }
}

Then in one of your modules you can load a template like this:

var template = require('./template.html');

$('#el').html(template({key: 'value'});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top