繁体   English   中英

使用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文件和新创建的template.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

我在index.html中引用了dist / app.js文件

我遇到的问题是我的应用程序内部,我引用了一些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路由器中引用了html文件:(function(){'use strict';

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM