Angularjs 如何从网页包中包含供应商捆绑包,以便在karma test runner中使用

Angularjs 如何从网页包中包含供应商捆绑包,以便在karma test runner中使用,angularjs,typescript,webpack,karma-runner,karma-webpack,Angularjs,Typescript,Webpack,Karma Runner,Karma Webpack,我有一个AngularJS 1.x项目是用TypeScript编写的,我正在使用Webpack。我现在正试图用我为我的一个服务编写的示例测试来设置模块 我遵循了中的示例karma配置文件,现在就有这个: module.exports = function (config) { config.set({ basePath: '../', frameworks: ['jasmine', 'karma-typescript'], files: [ /

我有一个AngularJS 1.x项目是用TypeScript编写的,我正在使用Webpack。我现在正试图用我为我的一个服务编写的示例测试来设置模块

我遵循了中的示例karma配置文件,现在就有这个:

module.exports = function (config) {
  config.set({
    basePath: '../',
    frameworks: ['jasmine', 'karma-typescript'],
    files: [
            //Add library includes here...
      'app/**/*.ts'
    ],
    exclude: [
    ],
    preprocessors: {
      'app/**/*.ts': ['karma-typescript']
    },
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['PhantomJS'],
    singleRun: false,
    concurrency: Infinity
  })
}
当我运行我的测试任务时,我得到一个错误,说找不到angular。我知道为什么,因为在我的karma配置文件中,我还没有添加应用程序所需的任何库。有没有办法让karma加载到我的webpack配置文件要构建的供应商捆绑包文件中,而不是单独添加这些文件

const path = require('path');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpack = require('webpack');
const copy = require('copy-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
  entry: {
    main: './app/app.module.ts',
    vendor: [
      'jquery',
      'angular',
      'angular-animate',
      'angular-aria',
      'angular-cookies',
      'angular-material',
      'angular-messages',
      'angular-mocks',
      'angular-resource',
      'angular-sanitize',
      'angular-ui-bootstrap',
      'angular-ui-router',
      'angular-local-storage',
      'bootstrap',
      'less',
      'lodash',
      'moment',
      'ui-select',
      'leaflet',
      'iso-currency',
      'angular-leaflet-directive'
    ],
  },
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].bundle.js',
  },
  module: {
    rules: [
      {
        test: require.resolve('jquery'),
        use: [{
          loader: 'expose-loader',
          options: '$'
        }]
      }, {
        test: /\.less$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: ['css-loader', 'less-loader']
        })
      }, {
        test: require.resolve('moment'),
        use: [{
          loader: 'expose-loader',
          options: 'moment'
        }]
      },
      {
        test: /\.(png|woff|woff2|eot|ttf|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
        loader: 'url-loader'
      },
      {
        enforce: 'pre',
        test: /\.tsx?$/,
        use: 'source-map-loader'
      },
      {
        test: /\.ts?$/,
        exclude: /node_modules/,
        use: 'ts-loader'
      }
    ]
  },
  resolve: {
    extensions: ['.ts', '.js']
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendor',
      minChunks: Infinity
    }),
    new webpack.ProvidePlugin({
      $: "jquery",
      jQuery: 'jquery',
      'window.jQuery': 'jquery'
    }),
    new ExtractTextPlugin('./app.css'),
    new CleanWebpackPlugin(['dist']),
    new copy([
      { from: 'app' },
      { from: 'index.html' },
      { from: 'app/assets/fonts', to: 'assets/fonts' },
      { from: 'app/assets/iln18Support', to: 'assets/iln18Support' },
      { from: 'app/assets/images', to: 'assets/images' },
      { from: 'app/partials', to: 'partials' }
    ])
  ]
};
那么,我有没有办法告诉karma通过webpack包含我的vendor.bundle.js文件输出

我正在努力寻找好的例子\文档,如果有人能在这里向我推荐任何对我有帮助的,我将不胜感激


谢谢

通过创建一个名为
app/vendor.bundle.ts的新文件解决了这个问题

现在,我不再通过webpack配置导入所有外部供应商,而是将它们放在捆绑包文件中

vendor.bundle.ts
文件本身如下所示:
(我还认为,将供应商与网页包配置分离的方法可以使网页包配置更干净)

因此,在我的网页配置中,我现在只有一个入口点,如下所示:

module.exports = {
  entry: {
    vendor: './app/vendor.bundle.ts',
    main: './app/app.module.ts',
  }
}
...
在我的
karma.conf.js
中,我现在可以像这样将供应商作为单一入口点导入(注意,我的应用程序在这里也是一个单一入口点):


谢天谢地,现在几乎所有的文档都过时了,几乎没有人使用没有babel的typescript。这既简单又优雅:)
module.exports = {
  entry: {
    vendor: './app/vendor.bundle.ts',
    main: './app/app.module.ts',
  }
}
...
module.exports = function (config) {
  config.set({
    files: [
      // Vendors
      'app/vendor.bundle.ts',
      // App
      'app/app.module.ts',

      // Load tests
      'app/**/*spec.ts'
    ],
    preprocessors: {
      'app/**/*.ts': ['karma-typescript']
    },
    ...
  })
}