Webpack: using require for ng-include

前端 未结 4 1003

I\'m new to webpack and right now I\'m using it for the first time in one of my angular projects.

I want to use the require function in my html file in order to requ

4条回答
  •  余生分开走
    2020-12-14 16:25

    You can use HTML loader and angular $templateCache service

    angular
        .module('template',[])
        .run(['$templateCache', function($templateCache) {
            var url = 'views/common/navigation.html';
            $templateCache.put(url, require(url));
        }]);
    

    webpack loader config:

    {
        test: /\.html$/,
        loader: 'html',
        query: {
            root:sourceRoot
        }
    }
    

提交回复
热议问题