Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在Angular project中使用gulp处理html片段_Angularjs_Gulp - Fatal编程技术网

Angularjs 在Angular project中使用gulp处理html片段

Angularjs 在Angular project中使用gulp处理html片段,angularjs,gulp,Angularjs,Gulp,角度指令、控制器等使用的所有部分html模板都位于build文件夹中。我使用gulp来构建项目,它完成了所有常见的任务,比如清理目标文件夹、编译手写笔并将其放入构建文件夹、将bootstrap.css移到构建文件夹、浏览.js文件以及将mvoe移到构建文件夹。到现在为止,一直都还不错。。但是如何处理partials文件夹中的html模板呢 这些是简单地复制到构建文件夹吗 根据@JimL建议。。我正在使用browserify,我的主app.js如下所示 -client/ index.ht

角度指令、控制器等使用的所有部分html模板都位于build文件夹中。我使用gulp来构建项目,它完成了所有常见的任务,比如清理目标文件夹、编译手写笔并将其放入构建文件夹、将bootstrap.css移到构建文件夹、浏览.js文件以及将mvoe移到构建文件夹。到现在为止,一直都还不错。。但是如何处理partials文件夹中的html模板呢

这些是简单地复制到构建文件夹吗

根据@JimL建议。。我正在使用browserify,我的主app.js如下所示

-client/
     index.html
     node_modules/
       ..
       ..
     js/
       -controllers/   
       -directives/
       -services/
         app.js
     partials/
         someHTML.html
         anotherHTML.html
     build/
        -app.js
        -custom.css
        ...

-server
   server.js

现在,模板缓存如何符合上述等式?将创建template.js文件并将其放置在build文件夹中。。这还不可用于浏览

您应该尝试使用Gulp Angular Templatecache之类的工具,该工具将使用$Templatecache服务在应用程序中直接绑定模板

/*jshint globalstrict: true*/
'use strict';

require('es5-shim');
require('es5-sham');
require('jquery');
require('angular');

var app = angular.module('app', [require('angular-ui-router')]);

require('./controllers');
require('./directives');
require('./services');

我建议您使用将所有html文件合并到一个js文件中。更容易加载(甚至可以包含在app.min.js文件中),对于每个部分只获得一个模板请求而不是一个模板请求的用户来说也很好:)现在我的指令/控制器使用的路径是“../partials/someTemplate.html”。。一旦我包含了模板缓存,这将如何更改?除了“文件夹向上”之外,它不会更改:)您引用缓存文件的方式相同way@JimL我已经编辑了上面的问题。我能够包括模板缓存和编译并获取template.js。。不确定如何将其包括在项目中。在gulp任务中,将选项standalone:true传递给templateCache。在应用程序之前包含模板js文件,然后注入模板模块(如ui路由器)
var templateCache = require('gulp-angular-templatecache');

gulp.task('html', function () {
    gulp.src('templates/**/*.html')
        .pipe(templateCache())
        .pipe(gulp.dest('public'));
});