【问题标题】:Using underscore templates with grunt browserify使用带有 grunt browserify 的下划线模板
【发布时间】:2014-03-19 15:14:02
【问题描述】:

我想预编译下划线模板并将它们包含在我的 grunt-browserify 的 app.js 目标文件中。

我知道有用于车把模板的选项 transform:hsbfy,但我怎样才能对下划线模板做同样的事情呢?

我尝试使用 node-underscorify 没有成功

【问题讨论】:

    标签: javascript templates underscore.js browserify


    【解决方案1】:

    您应该使用选项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']
            }
        }
    }
    

    然后在您的一个模块中,您可以加载这样的模板:

    var template = require('./template.html');
    
    $('#el').html(template({key: 'value'});
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-07
      • 2013-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多