user4217999
user4217999

Reputation:

How to add base path to gulp angular embed templates

I wrote a basic gulp angular embed templates task to convert all the directives with template URL to template. If I am using the relative path in my directive template URL, then I can see the conversion with this task is happening properly. But when I add the absolute path, to my directive html's, then this task is not appending the html template. I am still seeing the template URL after the task is completed.

In documentation base path for angular embed template i have seen that this task offers a base path, where it will convert all the template URL's with base bath.

This is what I tried:

directive.js:

(function() {
    'use strict';
    angular.module('testApp')

        .directive('test', test);

    function test() {
        return {
            restrict: 'E',
            templateUrl: basePath+'templates/test.html'
        }
    }
})();

gulpfile.js:

var gulp = require('gulp');
var embedTemplates = require('gulp-angular-embed-templates');

gulp.task('js:build', function () {
    gulp.src('src/app/**/*.js')
        .pipe(embedTemplates({
            options:{basePath:'/'}
        }))
        .pipe(gulp.dest('dist'));
});

// The default task (called when you run `gulp` from cli)
gulp.task('default', ['js:build']);

Upvotes: 2

Views: 778

Answers (1)

Arnd Brugman
Arnd Brugman

Reputation: 89

.pipe(embedTemplates({'basePath':'./'}))

worked for me :) Relative paths from the dir where gulp was run.

Docs could be better, leaving options. out would make this more clear.

Upvotes: 1

Related Questions