使用Grunt html2js和concat,我如何从concat js文件引用html文件
Using Grunt html2js and concat, how do I reference a html file from the concat js file
我有一个非常大的模块化AngularJS应用程序。我将Grunt设置为使用html2js从多个html文件中创建一个JS文件。
html2js: {
options: {
base: 'dol',
module: 'dol.templates',
singleModule: true,
useStrict: true,
htmlmin: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
}
},
main: {
src: ['app/modules/reporting/views/*.html'],
dest: 'tmp/templates.js'
}
},
然后对所有js文件和新创建的templates.js文件运行concat:
concat: {
options: {
separator: ';'
},
dist: {
src: ['tmp/*.js', 'app/app.js', 'app/app.controller.js', 'app/common/directives/directives.js', 'app/app.factory.js', 'app/modules/reporting/controllers/reports.controller.js', 'app/modules/reporting/reports.routes.js', 'app/xenon.custom.js'],
dest: 'dist/app.js'
}
},
我现在有一个文件,所有的js文件和html文件:app.js
我引用dist/app.js文件在我的index.html
我遇到的问题是在我的应用程序中,我引用了一些HTML文件,如:
// Layout Related Directives
directive('reportsSummary', function () {
return {
restrict: 'E',
templateUrl: appHelper.templatePath('modules/reporting/views/reportssummary.view')
};
}).
directive('reportsSidebarMenu', function () {
return {
restrict: 'E',
templateUrl: appHelper.templatePath('modules/reporting/views/reports.sidebar.menu')
};
}).
directive('reportsFooter', function () {
return {
restrict: 'E',
templateUrl: appHelper.templatePath('modules/reporting/views/reports.footer')
};
});
当我运行部署的应用程序时,我得到一个错误,指出它无法找到这些文件。当我在本地运行应用程序时,它运行良好,因为文件位于正确的路径中。
问题是:当部署应用程序时,我如何在我的代码中引用这些html文件,因为它们现在驻留在dist/app.js
我还在我的ui-router中引用了html文件:(function () {使用严格的;
angular
.module('dol')
.config(reportsConfig);
reportsConfig.$inject = ['$stateProvider', '$urlRouterProvider'];
function reportsConfig($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/reports');
$stateProvider.state('reports',
{
url: '/reports',
templateUrl: 'app/modules/reportspage/views/reports.view.html',
controller: 'reportsController'
});
}
}) ();
尝试在你的grunt任务中使用ngtemplates:
https://www.npmjs.com/package/grunt-angular-templates相关文章:
- 如何播放部分音频文件
- 从桌面读取python文件时高亮显示代码
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 如何使用WCF服务和javascript表单post上传.doc文件
- 当包含另一个asp文件时,是否也包含所有引用的样式和脚本页面
- 如何在生成下载文件时显示加载动画
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- Nodejs模块文件和concat
- Grunt文件Concat和css最小错误
- 使用requirejs加载一个包含多个类的文件(grunt-concat)
- Gulp-Concat文件的顺序然后是任何其他的js文件
- 基于 MVC 区域的 Concat 文件
- gulp-concat:如何确保文件最后连接
- 使用Grunt从两个不同来源获得的Concat和Uglify JS文件
- 首先执行concat目录递归文件
- 使用grunt-contrib-concat组合JSON文件
- 使用Grunt html2js和concat,我如何从concat js文件引用html文件
- Grunt useminPrepare和usemin无法处理多个任务和文件(concat失败)
- gull-concat只连接两个(半个)JS文件
- 如何使用broccoli.js获得一个简单的文件树进行concat