0

I have a file structure where the templates are located in different folders but the build task puts them all into a single folder. I wish to strip all the different prefixes from the files and prepend the correct build prefix.

This works to load all the templates

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

I am looking for the same functionality in the preprocessor, something like this

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

Is there a way to remove the entire prefix up to the template.html?

my folder structure is as follows:

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

The build folder is as follows

build
    assets
        components
            email_template.html
            phone_template.html

Thanks in advance.

JordanC
  • 131
  • 1
  • 1
  • 10
  • Why? `ngHtml2Js` puts all the templates into the `$templateCache` as strings anyway. It shouldn't be writing individual template files – Phil Apr 04 '16 at 23:37
  • @Phil ngHtml2Js caches the templates from the src directory but when my karma tests try to load the build files it fails. ngHtml2Js strips the src prefix and adds the build prefix so that when the karma test tries GET /assets/components/email_template.html, it gets served the template. – JordanC Apr 04 '16 at 23:42

1 Answers1

2

you are probably looking for this

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;
  },
}

It is described in the repo. https://github.com/karma-runner/karma-ng-html2js-preprocessor

sdfacre
  • 1,273
  • 7
  • 7
  • Thank you! Ended up using this in combined with a regular expression filepath.replace(/src\/components\/\w*\//i, '/assets/components/') – JordanC Apr 05 '16 at 00:34