2017-08-01 59 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$/,