2016-04-04 14 views
0

私はテンプレートが異なるフォルダにあるファイル構造を持っていますが、ビルドタスクはそれらをすべて1つのフォルダに入れます。私はファイルからすべての異なるプレフィックスを取り除き、正しいビルドプレフィックスの前に追加したいと思います。html2jsプリプロセッサ複数の接頭辞を取り除く

この私はプリプロセッサで同じ機能を探していますすべてのテンプレート

preprocessors: { 
    'src/components/**/*_template.html': ['ng-html2js'] 
} 

をロードするように働き、この

ngHtml2JsPreprocessor: { 
    stripPrefix: "src/components/**", 
    prependPrefix: "/assets/components", 
    moduleName: "templates" 
}, 

のようなものは、まで全体のプレフィックスを削除する方法はありますtemplate.html?次のように

私のフォルダ構造は次のとおりです。

src 
    components 
     email 
      directive.js 
      service.js 
      email_template.html 
     phone 
      directive.js 
      service.js 
      phone_template.html 

事前に

build 
    assets 
     components 
      email_template.html 
      phone_template.html 

感謝を次のようにビルドフォルダがあります。

+0

なぜですか? 'ngHtml2Js'はすべてのテンプレートを文字列として' $ templateCache'に入れます。それは個々のテンプレートファイルを書くべきではありません – Phil

+0

@Phil ngHtml2Jsはsrcディレクトリからテンプレートをキャッシュしますが、私のカルマテストがビルドファイルをロードしようとすると失敗します。 ngHtml2Jsはsrc接頭辞を取り除き、カルマテストがGET /assets/components/email_template.htmlを試みるときにテンプレートを提供するようにビルド接頭辞を追加します。 – JordanC

答えて

2

あなたは、おそらくそれは、レポに記載されている。この

ngHtml2JsPreprocessor: { 
    // define a custom transform function 
    // - cacheId returned is used to load template 
    // module(cacheId) will return template at filepath 
    cacheIdFromPath: function(filepath) { 
    // example strips 'public/' from anywhere in the path 
    // module(app/templates/template.html) => app/public/templates/template.html 
    var cacheId = filepath.strip('public/', ''); 
    **do whatever you need to construct the path** 
    return cacheId; 
    }, 
} 

を探しています。 https://github.com/karma-runner/karma-ng-html2js-preprocessor

+0

ありがとう!これを正規表現のfilepath.replace(/ src \/components \/\ w * \/i、 '/ assets/components /')と組み合わせて使用​​して終了しました。 – JordanC

関連する問題