我写了一个基本的 gulp angular 嵌入模板任务来将所有带有模板 URL 的指令转换为模板。如果我在我的指令模板 URL 中使用相对路径,那么我可以看到此任务的转换正在正常进行。但是当我将绝对路径添加到我的指令 html 时,此任务不会附加 html 模板。任务完成后我仍然看到模板 URL。
在文档中 base path for angular embed template我已经看到此任务提供了一个基本路径,它将在其中转换所有带有 base bath 的模板 URL。
这是我尝试过的:
指令.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']);
最佳答案
.pipe(embedTemplates({'basePath':'./'}))
对我有用 :) 运行 gulp 的目录的相对路径。
文档可能会更好,留下选项。 out 会让这更清楚。
关于javascript - 如何将基本路径添加到 gulp Angular 嵌入模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41134348/