html2js preprocessor stripping multiple prefixes

371 Views Asked by At

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.

1

There are 1 best solutions below

1
sdfacre On BEST ANSWER

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