Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path for template files being removed #72

Closed
prettycode opened this issue Feb 17, 2015 · 5 comments
Closed

Path for template files being removed #72

prettycode opened this issue Feb 17, 2015 · 5 comments

Comments

@prettycode
Copy link

Let's say I have this in my gulp file:

var paths = [ 
    'Scripts/app/components/chart/chart.tpl.html',
    'Scripts/app/factories/httpErrorInterceptor/httpErrorInterceptor.tpl.html'
];

gulp.src(paths)
    .pipe(angularTemplatecache({ standalone: true }))

The output I get is:

angular.module("templates", []).run(["$templateCache", function($templateCache) {$templateCache.put("chart.tpl.html", ...
$templateCache.put("httpErrorInterceptor.tpl.html","...

Am I correct in thinking that there's no way to get this output below instead?

angular.module("templates", []).run(["$templateCache", function($templateCache) {$templateCache.put("Scripts/app/components/chart/chart.tpl.html", ...
$templateCache.put("Scripts/app/factories/httpErrorInterceptor.tpl.html","...

I don't understand why the path should be shaved off. What if I want to keep them (as I do)?

Looking in index.js of the master source, on line 49, I see that the original file path is being stripped via file.path.replace(base || file.base, ''). Why do this? gulp-templatecache doesn't do this—you have to explicitly tell it to strip out part of the path if you want it removed.

@prettycode
Copy link
Author

I can use base argument as a function.

@bigmeech
Copy link

@prettycode hi could you please provide some sample code on how you solved this issue. I'm having the same.

@prettycode
Copy link
Author

@bigmeech for me, on Windows, this is what did the trick:

var templateRootDir = __dirname,
    templateOptions = {
        root: '/',
        base: function (file) {
            return file.path.replace(templateRootDir, '').replace(/\\/g, '/');
        }
    };

...
angularTemplatecache(templateOptions)
...

Hope this helps!

@tinyfly
Copy link

tinyfly commented Jun 17, 2015

Thanks @prettycode This was driving me crazy.

In my case setting base: process.cwd() worked great for me since the gulpfile is in the root of the repo.

@bennekrouf
Copy link

@tinyfly +1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants