0

モジュール化された非常に大きな AngularJS アプリケーションがあります。html2js を使用して、複数の html ファイルから単一の JS ファイルを作成するように Grunt をセットアップします。

    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 ファイルを含む 1 つのファイルができました: 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 ファイルをコードで参照するにはどうすればよいですか。

また、ui-router で 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'
        });
}

})();

4

1 に答える 1

0

grunt タスクで ngtemplates を使用してみてください。

https://www.npmjs.com/package/grunt-angular-templates

于 2015-07-10T19:59:44.790 に答える