NPM模块的TemplateCache未加载(AngularJS 1.X和Webpack)

时间:2018-05-14 18:27:38

标签: angularjs webpack gulp angular-strap angular-templatecache

我使用fountain-angular yeoman生成器和webpack创建了一个角度1.x项目,用于模块管理。

然后我添加了angular-strap作为此项目的依赖项。

现在,当我尝试使用像标签这样的角带式插件或在我的应用程序中选择时,我无法获得加载这些组件的相应模板。得到以下控制台错误。

  

错误:[$ compile:tpload]无法加载模板:tab / tab.tpl.html(HTTP状态:未定义未定义)

我不确定是否必须更改webpack配置文件中的任何内容才能正确加载这些模板。以下是我的配置现在的样子。

const webpack = require('webpack');
const conf = require('./gulp.conf');
const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const FailPlugin = require('webpack-fail-plugin');
const autoprefixer = require('autoprefixer');

module.exports = {
  module: {
    rules: [
      {
        test: /\.json$/,
        loaders: [
          'json-loader'
        ]
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'eslint-loader',
        enforce: 'pre'
      },
      {
        test: /\.(css|scss)$/,
        use: [
          'style-loader',
          'css-loader',
          {
            loader: 'postcss-loader',
            options: {
              config: {
                path: './postcss.config.js'
              },
              plugins: () => [require('autoprefixer')]
            },
          },
          'sass-loader',
        ]
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loaders: [
          'ng-annotate-loader',
          'babel-loader'
        ]
      },
      {
        test: /\.html$/,
        loaders: [
          'html-loader'
        ]
      }
    ]
  },
  plugins: [
    new webpack.ProvidePlugin({
      moment: 'moment',
      agGrid: 'ag-grid'
    }),
    new webpack.ContextReplacementPlugin(/\.\/locale$/, 'empty-module', false, /js$/),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.NoEmitOnErrorsPlugin(),
    FailPlugin,
    new HtmlWebpackPlugin({
      template: conf.path.src('index.html')
    }),
    new webpack.LoaderOptionsPlugin({
      options: {
        postcss: () => [autoprefixer]
      },
      debug: true
    })
  ],
  devtool: 'source-map',
  output: {
    path: path.join(process.cwd(), conf.paths.tmp),
    filename: 'index.js'
  },
  entry: `./${conf.path.src('index')}`
};

下面是我的index.js文件。

import angular from 'angular';
import 'angular-sanitize';
import 'angular-toastr';
import 'todomvc-app-css/index.css';
import {TodoService} from './app/todos/todos';
import {App} from './app/containers/App';
import {Header} from './app/components/Header';
import {MainSection} from './app/components/MainSection';
import {TodoTextInput} from './app/components/TodoTextInput';
import {TodoItem} from './app/components/TodoItem';
import {Footer} from './app/components/Footer';
import 'angular-ui-router';
import 'angular-strap';
import 'angular-cookies';
import '@exalink/ui-components/dist/xl.ui-components';
import routesConfig from './routes';
import * as agGrid from 'ag-grid';
import './index.scss';

agGrid.initialiseAgGridWithAngular1(angular);

angular
  .module('app', ['ngSanitize', 'ngCookies', 'agGrid', 'mgcrea.ngStrap', 'ui.router', 'toastr', 'xl.uiComponents'])
  .config(routesConfig)
  .service('todoService', TodoService)
  .component('app', App)
  .component('headerComponent', Header)
  .component('footerComponent', Footer)
  .component('mainSection', MainSection)
  .component('todoTextInput', TodoTextInput)
  .component('todoItem', TodoItem);

下面是我的header.html,我添加了下面的模板,该模板使用了angular-strap中的bs-tabs。

<div bs-active-pane="$ctrl.tabs.activeTab" bs-tabs>
  <div ng-repeat="tab in $ctrl.tabs" data-title="{{ tab.title }}" name="{{ tab.title }}" disabled="{{ tab.disabled }}" ng-bind="tab.content" bs-pane>
  </div>
</div>

我相信我错过了一些非常直接和简单的事情。我对webpack很陌生,任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:0)

您仅导入 import 'angular-strap'; 但仍需要包括angular-strap.tpl.min.js http://mgcrea.github.io/angular-strap/

导入'angular-strap.tpl.js'以及