2017-08-01 4 views
0

私は、Laravel 5で開発された既に構築されたシステムで作業しています.htmlに関しては、以前の開発者はBackboneを使用していましたが、レイアウトには2つのJSファイルしか存在しません。 1つのファイルでは、すべての基本的な必須jsファイルとすべてのJSファイルのバックボーンを結び付けます。彼はこのファイルをadmin.jsと命名した。彼は別のファイルを使い、すべてのhtmlテンプレートをあらかじめコンパイルされたハンドルバーテンプレートとして使用していて、それをadmin_template.jsと名づけました。彼はシステム全体でこれらの2つのjsファイルのみを使用します。私はサーバーコードにアクセスできますが、彼がどのビルドシステムを使用したかを示すファイルはありません。サーバーにはpackage.jsonはありません。私は彼が自分のローカルでこれらのものを使用していただろうと思うし、これらのものをリポジトリまたはサーバーにプッシュしたことはありません。Gruntハンドルバープリコンパイラテンプレート

深く掘削することによって、私は彼がGruntを使用したことを知るようになりました。私は彼がすでに生成したようにadmin.jsファイルを生成するように管理しています。テンプレートの場合、彼はJSTを使用しています。私は検索して1つを見つけたgrunt-contrib-handlebars。私はテンプレートファイルを生成することができましたが、それは既存のファイルと100パーセント一致していません。例えば、ここでは、既存のファイル

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では、我々はthis.compilerInfo = [4,'>= 1.0.0'];ようcompilerInfoを持っており、私の中で、それは私が生成されたファイルでプロジェクトを実行しようとすると、それは{"compiler":[7,">= 4.0.0"]

のようであるいくつかの場所でそれをいくつかの場所で行方不明とされた1を生成し、それが

`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は、そのコンパイラのバージョンはオリジナルのものは、コンパイラvを持つハンドルバージョン4の間に導入されたことを意味= 4.コンパイラv 5にはハンドルバー2.0.0-alphaが付属していました。これは、ハンドバールに依存するいくつかのgrunt-contrib-handlebarsを必要とすることを意味します。vリリースノートによれば、v0.8.0最後の1つはハンドルバー1.xに依存します。 これは、package.json内のプリコンパイラを"grunt-contrib-handlebars" : "=0.8.0"のようにダウングレードする必要があることを意味します。 また、実行時のハンドルバーを最新のものに更新して、プリコンパイルされたテンプレートが古いものでなくてもブラウザでエラーなしで実行されるようにすることができます。

名前を同じにする必要があります。cwd: './public/assets/js/'またはその一部を取り除くために、オプションに

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

のようなものを追加します。私はあなたのようなあなたのgruntfileのコンパイルオプションのセクションでcwdを設定することができると思います。

3番目:プロジェクトで部分的な部分が使用されている可能性があります。それらはテンプレート内に{{> myPartialName}}のように見えます。その場合、またファイルでもあれば、それらを部分タスクとしてそれらのタスクに追加する必要があります。 partialRegex: /^myPartialName|^myOtherPartial.hbs$/,