2017-08-01 64 views
0

我正在开发Laravel 5中已建好的系统。对于html,以前的开发人员已经使用了Backbone,但他已经使用了一些任务管理器。布局中只有两个JS文件。在一个文件中,他将所有基本需要的js文件和主干的所有JS文件拼接起来。他将这个文件命名为admin.js。他使用了另一个文件,并将所有html模板用作预编译的句柄模板,并将其命名为admin_template.js。他只在系统中使用这两个js文件。我有服务器代码的访问权限,但是没有可以指示他使用哪个构建系统的文件。服务器上没有package.json。我想他会在他的本地使用这些东西,并且从不将这些东西推送到任何存储库或服务器。Grunt Handlebar预编译器模板

通过挖深,我已经知道他已经使用Grunt。我已经管理生成admin.js文件,就像他已经生成。对于他使用的模板JST。我已搜索并找到一个grunt-contrib-handlebars。我已经设法生成模板文件,但它不与现有文件百分百匹配。例如,下面是现有的文件

this["JST"] = this["JST"] || {}; 
    this["JST"]["admin/Modules/Base/Templates/InModalMessageTemplate.html"] = 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, helper, options, functionType="function", escapeExpression=this.escapeExpression, self=this, helperMissing=helpers.helperMissing; 

    function program1(depth0,data) { 

     var buffer = "", stack1, helper; 
     buffer += "\n<div id=\"inModalMessageWrap\" class=\"bs-callout bs-callout-danger "; 
     if (helper = helpers.type) { stack1 = helper.call(depth0, {hash:{},data:data}); } 
    else { helper = (depth0 && depth0.type); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; } 
    buffer += escapeExpression(stack1) 
+ "\">\n"; 
    return buffer; 
} 

的内容和换同款,检查我的文件

this["JST"] = this["JST"] || {}; 

this["JST"]["./public/assets/js/admin/Modules/Base/Templates/InModalMessageTemplate.html"] = Handlebars.template({"1":function(container,depth0,helpers,partials,data) { 
var helper; 

    return "<div id=\"inModalMessageWrap\" class=\"bs-callout bs-callout-danger " 
+ container.escapeExpression(((helper = (helper = helpers.type || (depth0 != null ? depth0.type : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"type","hash":{},"data":data}) : helper))) 
+ "\">\n"; 
},"3":function(container,depth0,helpers,partials,data) { 
var helper; 

    return "<div id=\"inModalMessageWrap\" class=\"bs-callout bs-callout-success " 
+ container.escapeExpression(((helper = (helper = helpers.type || (depth0 != null ? depth0.type : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"type","hash":{},"data":data}) : helper))) 
+ "\">\n"; 
} 

检查前1有一些function program1(depth0,data) {但在我产生1它不是。在以往的1中,我们有compilerInfo像this.compilerInfo = [4,'>= 1.0.0'];和我产生1它缺少一些地方,它在某些地方它就像{"compiler":[7,">= 4.0.0"]

当我试图用我生成的文件运行项目,它说

`TypeError: templateSpec.call is not a function` 

我搜索了这个错误,它是关于车把版本问题。我已经安装了上述版本,但这个错误不会在任何地方发生。这是我的gruntfile看起来像

module.exports = function(grunt) { 
var libFiles = [ 

    './public/assets/js/admin/Modules/**/*.js' 
]; 
// Project configuration. 
grunt.initConfig({ 
    pkg: grunt.file.readJSON('package.json'), 
    concat: { 
     options: { 
      stripBanners: true, 
      banner: '/*! Compiled on: <%= grunt.template.today("mm-dd-yyyy") %> */' + '\n\n', 
      separator: "\n", 
      process: function (src, filepath) { 
       return '// Source: '+filepath+'\n\n' + src+'\n' 
      } 

     }, 
     dist: { 
      src: libFiles, 
      dest: './public/assets/js/compiled/admin.js', 
     }, 
    }, 
    handlebars: { 
     compile: { 
      options: { 
       namespace: 'JST' 
      }, 
      files: { 
       './public/assets/js/compiled/my_template.js': ['./public/assets/js/admin/Modules/**/*.html'] 
      } 
     } 
    } 
}); 

// Load the plugin that provides the "uglify" task. 
grunt.loadNpmTasks('grunt-contrib-concat'); 

grunt.loadNpmTasks('grunt-contrib-handlebars'); 
// Default task(s). 
    grunt.registerTask('default', ['concat', 'handlebars']); 

}; 

任何机构可以让我知道我怎么能解决这个问题,才能够产生精确的文件已经存在预编译车把模板?

回答

0

几件事情:

首先在"compiler":[7,">= 4.0.0"] 是车把编译版本和> = 4.0.0意味着,编译器版本车把版本期间引入4.原始之一具有编译器v = 4.编译器v 5带有把手2.0.0-alpha,这意味着你需要一些grunt-contrib-handlebars,它对handelbars v的依赖小于2.根据发行说明,v0.8.0是最后一个取决于把手1.x. 这意味着你必须在package.json中降级你的预编译器,如:"grunt-contrib-handlebars" : "=0.8.0"。 或者您可以将您的运行时句柄更新为最新版本,并希望预编译的模板在浏览器中运行时没有错误,即使它们不再是旧的。

然后,你必须使名称相同。我想你可以设置cwd像你gruntfile的编译部分选项:cwd: './public/assets/js/'或添加类似

processName: function(filePath) { 
    return filePath.replace("./public/assets/js/", ""); 
}, 

的选择,以摆脱部分。

第三:可能是项目使用偏分量。它们在模板中看起来像{{> myPartialName}},在这种情况下,如果它们也是文件,那么您需要将这些部分添加到您的grunt任务中。 partialRegex: /^myPartialName|^myOtherPartial.hbs$/,